You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.7 KiB

package ru.defend.defdevteam.tstu;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.w3c.dom.Text;
public class NewsFragment extends Fragment {
private static final String ARG_PARAM1 = "title";
private static final String ARG_PARAM2 = "text";
private static final String ARG_PARAM3 = "link";
private String mTitle;
private String mImgLink;
private String mText;
private OnFragmentInteractionListener mListener;
public NewsFragment() {
}
@Override
public void onResume() {
super.onResume();
if (getArguments() != null) {
mTitle = getArguments().getString(ARG_PARAM1);
mText = getArguments().getString(ARG_PARAM2);
mImgLink = getArguments().getString(ARG_PARAM3);
updateNewsFragment();
}
}
public static NewsFragment newInstance(NewsItemGroup group) {
NewsFragment newsFragment = new NewsFragment();
Bundle arg = new Bundle();
arg.putString(ARG_PARAM1, group.getTitle());
arg.putString(ARG_PARAM2, group.getText());
arg.putString(ARG_PARAM3, group.getLink());
newsFragment.setArguments(arg);
return newsFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void updateNewsFragment() {
TextView titleTextView = (TextView) getActivity().findViewById(R.id.floatingnews_title);
TextView textView = (TextView) getActivity().findViewById(R.id.floatingnews_content);
titleTextView.setText(mTitle);
textView.setText(mText);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_news, container, false);
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);
}
}