2012-11-29 59 views
1

Example 我不明白这个例子。 如何在我的程序如何将值从一个片段转移到另一个片段

申请我试着写在我的程序

一般使用,我可以。 但被替换的片段。 我不知道如何使用。

传递对象的值。

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     super.onCreateView(inflater, container, savedInstanceState); 
     View view = inflater.inflate(R.layout.templistmune, container, false); 
FragmentManager DS2 = getFragmentManager(); 
    FragmentTransaction DSE2 = DS2.beginTransaction(); 
    Fragment DF2 = DS2.findFragmentById(R.id.frameLayout4); 
    if (DF2 == null) { 
     String title = "Fragment A"; 
     templistview2 usermune = new templistview2(title); 
     DSE2.add(R.id.frameLayout4, usermune); 
     DSE2.addToBackStack(null); 
     DSE2.commit(); 
///////////////////////////////////////////////////////// 
     Bundle bundle = new Bundle(); 
     String SAS="50"; 
     bundle.putString("ST", SAS); 
     DF2.setArguments(bundle); 
//////////////////////////////////////////////// 
     } 

拾值的对象 templistview2.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     super.onCreateView(inflater, container, savedInstanceState); 
     View view = inflater.inflate(R.layout.templistmune2, container, false); 
//////////////////////////////////////////////////////////////////////////////////// 
    Bundle bundle = this.getArguments(); 
    String myST = bundle.getString("ST", SAS); 
///////////////////Error SAS cannot be resolved to a variable ///////////////// 



     return view; 

    } 

回答

1

你只需要添加添加BundleDF2为空...所以你的程序要么用NullPointerException沿某处崩溃行或运行但没有通过Bundle

等等场所

Bundle bundle = new Bundle(); 
    String SAS="50"; 
    bundle.putString("ST", SAS); 
    DF2.setArguments(bundle); 

的,如果结构之外。

相关问题