how to go from fragment to another fragment in kotlin code example
Example 1: how to go from fragment to another fragment in kotlin
purple.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Fragment fragment = new tasks();
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
Example 2: change fragment in android studio
Navigation.findNavController(view).navigate(R.id.action_fromFragment_toFragment);
Example 3: goto fragment from activity in kotlin intent
Intent notificationIntent = new Intent(context,MessagesFragment.class);
Example 4: how to start activity from fragment in kotlin
activity?.let{
val intent = Intent (it, Main::class.java)
it.startActivity(intent)
}