-1

in my MainActivity.java I have:

public class PlaceholderFragment extends Fragment {


    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

        //View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        LinearLayout ll = (LinearLayout )inflater.inflate(R.layout.fragment_main, container, false);
        //EditText editText1 = (EditText) ll.findViewById(R.id.editText1);            
        //return rootView;
        if (Global.globalInt==1){
            EditText editText1 = (EditText)ll.findViewById(R.id.editText1);
            Intent intent=getIntent();
            String s=intent.getStringExtra("stringa");
            editText1.setText(s,TextView.BufferType.EDITABLE);
            Global.globalInt=0;
            short y=9;
        }
        return ll;
    }
}

but I have an error: This fragment inner class should be static (com.example.test.MainActivity.PlaceholderFragment).

If I write public static class PlaceholderFragment extends Fragment {

I have another error: public static class PlaceholderFragment extends Fragment { How to resolve this problem?

thanks

bwegs
  • 3,769
  • 2
  • 30
  • 33
user3589887
  • 139
  • 2
  • 13
  • possible duplicate of [Passing data between a fragment and its container activity](http://stackoverflow.com/questions/9343241/passing-data-between-a-fragment-and-its-container-activity) – Andrew Schuster Jun 30 '14 at 14:52

3 Answers3

1

A fragment can get its Activity by calling getActivity(). Then you can get the intent: getActivity().getIntent().

brummfondel
  • 1,202
  • 1
  • 8
  • 11
0

Fragments do not invoked by intents so you could not get info from them. You could pass what you need when doing FragmentTransactions or by link to your activity by getActivity()

dimak
  • 36
  • 4
0

At the creation of the Fragment, before adding/replacing it into the container, you can set the arguments of the Fragment via the setArguments(Bundle bundle) function call:

PlaceHolderFragment phFragment = new PlaceHolderFragment();
phFragment.setArguments(intent.getExtras());
getSupportFragmentManager().beginTransaction().replace(R.id.container, phFragment).addToBackStack(null).commit();
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428