1

Example I do not understand this example. How to apply in my program

I try to write In my program

General use that I can. But replaced fragment. I do not know how to use.

Pass the value of the object.

    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);
////////////////////////////////////////////////
        }

The pick value the object 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;

    }
Community
  • 1
  • 1
HLto Dm
  • 275
  • 2
  • 5
  • 13

1 Answers1

1

You're only adding adding the Bundle when DF2 is null... so your program will either crash with a NullPointerException somewhere along the line or run but not have the Bundle passed.

So place

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

outside the if structure.

A--C
  • 36,351
  • 10
  • 106
  • 92