我有片段活动,其中包含用于片段转换的Framelayout。名为LeadActiviy
的片段在SherlockListFragment
的方法Asynctask
内容AsyncTask
块语句中扩展onPostExcute
包含else
。在else
块中,由ItemNotFound
替换的当前片段扩展了Fragment。按下后退按钮后,在framelayout中设置ItemNotFound
的内容后,它的当前状态仍然存在。没有出现它以前的片段。请帮我解决问题 -
来自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();
}
}
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;
}
}
答案 0 :(得分:0)
您可以看到我的解决方案here。
我有一个ViewPager
,其中有三个页面包含Fragments
。在第一页中,我有ListFragment
和onListItemClick
我将Fragment
替换为另一个Back Button
。按下ListFragment
后,我会返回{{1}}。