How To Call Fragment From Onclicklistener
I am working in Fragment. i want to call one fragment from onClickListener. how can i do that? This is my code. from the else part i have to call one fragment..how to do that?
Solution 1:
There are many ways to replacing Fragments. but I follow the way below:
Create addFragmentMethod() like below
publicvoidaddFragments(Fragment fragment) {
FragmentManagermanager= getSupportFragmentManager();
FragmentTransactionft= manager.beginTransaction();
ft.replace(android.R.id.tabcontent, fragment);
ft.commit();
}
now override onAttach() like this
@OverridepublicvoidonAttach(Activity activity) {
this.activity = (YourActivity) activity;
myDetail = this.activity.myDetail;
super.onAttach(activity);
}
now just call
activity.addFragments(fragment);
Solution 2:
I think what you want is to call a method in another Fragment that is already added. This is done via the Activity that both Fragments share. There's a guide here: http://developer.android.com/training/basics/fragments/communicating.html
Post a Comment for "How To Call Fragment From Onclicklistener"