我已经显示了在网格中显示的项目列表,并且数据来自 webservice 。当我单击它需要进入新屏幕的项目时,但是当从这个屏幕来到具有 Grid 的屏幕时,布局被重新创建,但我想像活动一样保存实例,这样屏幕就不会再次创建。我能做些什么来实现这一目标?
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mfragmentManager = getActivity().getSupportFragmentManager();
mhandler=new Handler(this);
mLvAllDeals = (GridView) mview.findViewById(R.id.xLvAllDeals);
mLvAllDeals.setCacheColorHint(0);
mLvAllDeals.setOnItemClickListener(this);
new MyDealsAsyncTask().execute();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAlDealName = new ArrayList<AllDealsData>();
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
if(arg0==mLvAllDeals)
{
position = arg2;
AllDealsData bean;
bean = mAlDealName.get(position);
Fragment frag = getFragmentManager().findFragmentById(R.id.inner_content2);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right);
if (!frag.getTag().equals("dealsinfo"))
{
Bundle args = new Bundle();
args.putString("dealid", bean.getId());
mdealinfo.setArguments(args);
ft.replace(R.id.inner_content2, mdealinfo, "dealsinfo");
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
}
}
}