Listfragment Oncreate Called Twice
how can I avoid that the onCreate method in the ListFragment ist called twice? I have search functions for my list. The search results might be shorter than the list, which I displ
Solution 1:
Put your fragment initialization code in if-else
like this:
if (savedInstanceState == null) {
listFragment = newPlantListFragment();
if(getSupportFragmentManager().findFragmentByTag(tag) == null){
try{
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_plantlist, listFragment,tag).commit();
}catch(Exception ex){
ex.printStackTrace();
CharSequencetext=this.getString(R.string.info_error_list);
Toasttoast= Toast.makeText(this, text, Toast.LENGTH_LONG);
toast.show();
}
}
//why you are force committing?//getSupportFragmentManager().executePendingTransactions();
}
It will solve your problem. Make sure to move listFragment = new PlantListFragment();
line inside if-else
.
Post a Comment for "Listfragment Oncreate Called Twice"