1

例子 这个例子我看不懂。如何申请我的计划

我尝试在我的程序中写

一般用的我都可以。但是替换了片段。我不知道怎么用。

传递对象的值。

    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;

    }
4

1 回答 1

1

您只是添加了Bundlewhen DF2is null... 所以您的程序要么在NullPointerException某个地方崩溃,要么运行但没有Bundle通过。

所以放置

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

在 if 结构之外。

于 2012-11-29T22:13:40.157 回答