我有 Fragment Activity,其中包含用于片段转换的 Framelayout。一个名为LeadActiviy
extends的片段SherlockListFragment
包含Asynctask
, inAsyncTask
的方法 onPostExcute
内容else
块语句。在else
块中,当前片段被ItemNotFound
扩展片段替换。ItemNotFound
在按下后退按钮时在 framelayout 中设置内容后,它的当前状态将保持不变并且不会出现其上一个片段。请帮我解决问题-
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;
}
}