I added a refresh button to action-bar. When fragment loading that refresh button is creating in the action-bar. I have more than one fragment in my application, problem is when move between fragments and go back using back button using back button, action bar menu refresh button drawing several times. like this
following code I'm using
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_seebo_tv, container, false);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.seebo_tv, menu);
}
in main activity
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar actions click
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.action_refresh:
fragment=new ProgressFragment();
FragmentManager fragmentManagerProgress = getFragmentManager();
fragmentManagerProgress.beginTransaction().replace(R.id.container, fragment).addToBackStack(null).commit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
how can I fix this?