I am making a car search application. I show the result in gridview, and also have a sliding menu on the right side (for the search filter). I made this application using fragments. In gridview, I have a load greater than the footer below, when I click on gridview 12th position, I start doing the following snippets as follows:
SearchDetailActivity.goToFragment(ProductDetailFragment.newInstance(map,position));
and in ProductDetailFragment I have a return button to go back to the previous snippet, like this:
SearchDetailActivity.goToFragment(SearchDetailFragment.newInstance(str_url));
Now that I'm back, the data is showing from point 0.
In goToFragment () I wrote this code:
public static void goToFragment(Fragment fragment) { Log.d("GoToFrag","sjdk>>"+fragment); Fragment tmp = fm.findFragmentByTag(fragment.getClass().getName()); if (tmp != null && tmp.isVisible()) return; ft = fm.beginTransaction(); ft.replace(R.id.main_fragment, fragment, fragment.getClass().getName()); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); currentTag = fragment.getClass().getName(); }
I want to avoid data reloading when I return from ProductDetailFragment. If I used Activity, then I can use onBackPressed () to return and avoid reloading, but in Fragment, when I pressed the back button, it reloads SearchDetatilFragment, which is very annoying .. Please help me .. Thanks in advance.
source share