1st Fragment
private EditText editText, editText2;
private Button button;
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_arman, container, false);
editText = view.findViewById(R.id.firstName);
editText2 = view.findViewById(R.id.lastName);
button = view.findViewById(R.id.buttonid);
button.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
String first = editText.getText().toString();
String last = editText2.getText().toString();
/*Bundle bundle = new Bundle(); bundle.putString("FirstName",first); bundle.putString("LastName", last);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Habib habib = new Habib(); habib.setArguments(bundle);
fragmentTransaction.replace(R.id.framelayout,habib).addToBackStack(null).commit();*/
Bundle bundle = new Bundle();
bundle.putString("FirstName", first);
bundle.putString("LastName", last);
Habib habib = new Habib();
habib.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.framelayout, habib).addToBackStack(null).commit();
}
});
return view;
2nd Fragment
private TextView fstt, lstt;
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_habib, container, false);
Bundle bundle = getArguments();
String firstname = bundle.getString("FirstName");
String lastname = bundle.getString("LastName");
fstt = view.findViewById(R.id.fst);
lstt = view.findViewById(R.id.lst);
fstt.setText(firstname);
lstt.setText(lastname);
return view;
}
0 Comments