Answer the question
In order to leave comments, you need to log in
How to control the simultaneous launch of fragments on click on a list item?
There is a fragment with a list, by clicking on an element of the list, a new fragment is created, and it is added to the FragmentManager, the fragment with the list is displayed and hidden. standard task. The problem is that if you click on two list items at the same time, then two fragments will be created and placed in the FragmentManager and displayed at the same time, and it is desirable that only one fragment be created.
executePendingTransactions() does not help
Now implemented with a trigger as a boolean variable that skips the click event if it has already been clicked, but until the fragment called by clicking on the list item is destroyed. Information about the destruction of a detailed fragment is passed through an interface that implements a fragment with a list.
Is it possible to do it somehow differently?
public class ListFragment extends Fragment implements DetailFragmentFragment.onDetailFragmentLifeCycleListener {
private boolean isTransactionPerforming = false;
...
@Override
public void onClick(Data someData) {
if (!isTransactionPerforming) {
isTransactionPerforming = true;
} else {
return;
}
DetailFragment DetailFragment = new DetailFragment();
DetailFragment.setMyData(someData);
DetailFragment.setFragmentVisible();
DetailFragment.setDetailLifeCycleListener(this);
getActivity().getSupportFragmentManager()
.beginTransaction()
.hide(currntListFragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
.add(R.id.List_frameLayout, DetailFragment)
.addToBackStack("details")
.commitAllowingStateLoss();
}
@Override
public void onShown() {
isTransactionPerforming = false;
}
...
}
public class DetailFragment extends Fragment {
...
@Override
public void onDestroy() {
super.onDestroy();
if (mDetailLifeCycleListener != null)
mDetailLifeCycleListener.onShown();
}
...
public onDetailLifeCycleListener mDetailLifeCycleListener;
public void setDetailLifeCycleListener(onDetailLifeCycleListener mDetailLifeCycleListener) {
this.mDetailLifeCycleListener = mDetailLifeCycleListener;
}
public interface onDetailLifeCycleListener {
public void onShown();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question