[英]Press back button current fragment persist not restore previous fragment
I have Fragment Activity which contains a Framelayout for fragment transition. 我有片段活动,其中包含用于片段过渡的帧布局。 A fragment named LeadActiviy
extends SherlockListFragment
contains Asynctask
, in AsyncTask
's method onPostExcute
contents else
block statement. 名为LeadActiviy
的片段扩展了SherlockListFragment
其中包含Asynctask
,在AsyncTask
的方法onPostExcute
内容中的else
语句中。 In else
block current fragment replaced by ItemNotFound
extends Fragment. 在else
被ItemNotFound
替换的当前片段扩展了Fragment。 After set the contents of ItemNotFound
in framelayout when press back button it's current state persist & not appear its previous fragment. 在按后退按钮时,在framelayout中设置ItemNotFound
的内容后,其当前状态保持ItemNotFound
,并且不会显示其先前的片段。 Please help me to solve issue- 请帮助我解决问题-
Code of AsyncTask's method onPostExecute from LeadActivity ... LeadActivity的AsyncTask方法onPostExecute的代码...
protected void onPostExecute(String file_url){
pDialog.dismiss();
//FragmentManager fm=getFragmentManager();
//final FragmentTransaction ft=fm.beginTransaction();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if(success==1){
// TODO Auto-generated method stub
ListAdapter adapter = new SimpleAdapter(
getActivity(), leadlist,R.layout.leadlistview, new String[] { Tag_Lead},
new int[] { R.id.textView6});
// updating listview
setListAdapter(adapter);
//get leads of order
ListView lv=getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String pid=((TextView) arg1.findViewById(R.id.textView6)).getText().toString();
LeadDetail frag=new LeadDetail();
Bundle bnd=new Bundle();
bnd.putString("lead",pid);
frag.setArguments(bnd);
FragmentManager fm=getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.replace(R.id.content_frame, frag);
ft.addToBackStack(null);
ft.commit();
}
});
}
else {
String e="Lead Not Found";
ItemNotFound frag=new ItemNotFound();
//Frag1 frag=new Frag1();
Bundle bnd=new Bundle();
bnd.putString("data",e);
frag.setArguments(bnd);
FragmentManager fm1=getFragmentManager();
FragmentTransaction ft1=fm1.beginTransaction();
ft1.replace(R.id.content_frame, frag,st);
ft1.addToBackStack(st);
ft1.commit();
}
}
Code for ItemNotFound............. ItemNotFound的代码.............
public class ItemNotFound extends SherlockFragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
super.onCreate(savedInstanceState);
View V = inflater.inflate(R.layout.itemnotfound, container, false);
TextView tv=(TextView)V.findViewById(R.id.textView7);
Bundle bnd=this.getArguments();
String s=bnd.getString("data");
tv.setText(s);
return V;
}
}
You can see my solution here . 您可以在这里看到我的解决方案。
I have a ViewPager
with three pages which contains Fragments
. 我有一个包含三个页面的ViewPager
,其中包含Fragments
。 In first page, I have a ListFragment
and onListItemClick
I replace that Fragment
with another one. 在第一页中,我有一个ListFragment
和onListItemClick
我用另一个替换该Fragment
。 When Back Button
is pressed, I go back to ListFragment
. 当按下Back Button
,我返回到ListFragment
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.