Answer the question
In order to leave comments, you need to log in
How to call a method in an activity from a fragment?
I can not call a method from a fragment in the Main Activity
so I try to call it in the activity
а
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_progress_show) {
progress_menu_item.setActionView(R.layout.menu_item_layout);
//ТАК Я ЕГО ПЫТАЮСЬ вЫЗвАТЬ в mAİN ACTİVİTY
TwoFragment fragment = new TwoFragment();
fragment. Refress();
return true;
}
return super.onOptionsItemSelected(item);
}
А вОТ МЕТОД вО ФРАГМЕНТЕ
}
public void Refress(){
mWebView.reload();
}
}
Answer the question
In order to leave comments, you need to log in
You are creating a new fragment in the activity instead of looking for the old fragment.
1. add a tag to the fragment in the FragmentTransaction.add
method
2. use the appropriate method to find the fragment
findFragmentByTag
findFragmentById
Understanding this mess is certainly not the most pleasant experience, but as I understand it, you simply create a new fragment in onOptionsItemSelected , but you want to do something in an existing one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question