I have a Tablayout
in main and I want move from a fragment to tablayout
to new fragment
My code :
public void onClick(View v) {
Fragment fragment = new Main2Activity();
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(container.getId(), fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
And New Fragment :
public View onCreateView(LayoutInflater inflater,ViewGroup viewGroup, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main2, viewGroup, false);
Toast.makeText(view.getContext(), "...", Toast.LENGTH_SHORT).show();
return view;
}
But when I clicked on TextView
the Toast is showed but activity_main2
is not show
The first fragment
The second fragment
Communication among fragment can only possible through interface and implementing that interface into parent activity. you can take the help from https://developer.android.com/training/basics/fragments/communicating
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.