0

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


   }


}
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
user3247335
  • 181
  • 2
  • 5
  • 16

1 Answers1

1

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

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • Hi it works thanks, i just had to restart my eclipse. It was tripping.. Do you have any idea how i will take a bundle of strings from the MainActivity Class to the Fragment Class – user3247335 Mar 30 '14 at 19:22
  • @user3247335 check this http://stackoverflow.com/questions/12739909/send-data-from-activity-to-fragment-in-android – Raghunandan Mar 30 '14 at 19:23