package com.bcoder.myapplication;
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.Button;
import android.widget.TextView;
public class TestFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM3 = "param3";
private String mParam1;
private String mParam2;
private String mParam3;
TextView mTextView1;
TextView mTextView2;
TextView mTextView3;
Button button1;
View fragmentView;
public TestFragment() {
// Required empty public constructor
}
public static TestFragment newInstance(String param1, String param3) {
TestFragment fragment = new TestFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM3, param3);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam3 = getArguments().getString(ARG_PARAM3);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
fragmentView = inflater.inflate(R.layout.fragment_test, container, false);
initViews();
mTextView1.setText(mParam1);
mTextView2.setText(mParam2);
mTextView3.setText(mParam3);
return fragmentView;
}
private void initViews() {
mTextView1 = (TextView) fragmentView.findViewById(R.id.textview1);
mTextView2 = (TextView) fragmentView.findViewById(R.id.textview2);
mTextView3 = (TextView) fragmentView.findViewById(R.id.textview3);
button1 = (Button) fragmentView.findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mParam1 = "banana2";
mTextView1.setText(mParam1);
mParam2 = "apple";
mTextView2.setText(mParam2);
mParam3 = "pear click";
getArguments().putString(ARG_PARAM3, mParam3);
mTextView3.setText(mParam3);
}
});
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
}
@Override
public void onDetach() {
super.onDetach();
}
}