user3247335
user3247335

Reputation: 163

Android, Java: Bundles & Views for Fragments

I have a fragment, that i want to put a textview which will have a 3 strings stored in it from the 'Main Activity'

The strings that I need to pass will come from the Main Activity and will be passed into FragmentClass

The issue is that its not recognising findViewById, i understand this is something to do with the views? Could someone advise me on how i could get this editText working and then how i can pass a bundle of strings from the MainActivity to the FragmentClass.

@SuppressLint("NewApi")
public class FragmentClass extends Fragment {

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

       //Inflate the layout for this fragment

      return inflater.inflate(
              R.layout.new_fragment, container, false);


      //  View rootView = inflater.inflate(R.layout.get_data, container, false);
    TextView FragmentTextView = (TextView)findViewById(R.id.FragmentTextView);


   }


}

Upvotes: 0

Views: 31

Answers (1)

Raghunandan
Raghunandan

Reputation: 133560

Change to

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

View view =inflater.inflate(R.layout.new_fragment, container, false);
TextView FragmentTextView = (TextView)view.findViewById(R.id.FragmentTextView);
return view;
}

Also you have @SuppressLint("NewApi") you have suppressed lint warning. Probably indicates that some features are available in new api's only. Do check your min sdk version in manifest

Upvotes: 1

Related Questions