1

我有 Fragment Activity,其中包含用于片段转换的 Framelayout。一个名为LeadActiviyextends的片段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;
    }

   }
4

1 回答 1

0

你可以在这里看到我的解决方案。

我有一个ViewPager三页,其中包含Fragments. 在第一页,我有一个ListFragment,我用另一个onListItemClick替换它。Fragment按下时Back Button,我回到ListFragment

于 2013-09-05T10:01:26.373 回答