Drew B
Drew B

Reputation: 465

How to display text in a TextView inside a Fragment

Seems like a simple question to me, but I can't figure it out. I have this code inside my Fragment:

myTextView.setText("Test");

However, this code brakes my app and I am unsure why. Perhaps this is a conflict with Views, but I still don't understand why it wont work. Any suggestions?

Upvotes: 0

Views: 6062

Answers (1)

Elior
Elior

Reputation: 3266

How did you set the content?

Edited my answer :) try this

 @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.xmlName,
        container, false);
    TextView tv= (TextView) **view**.findViewById(R.id.textViewName);
    tv.setText("yourText"); 
    return view;
  }

here is a tutorial for fragments : fragments tutorial

Upvotes: 3

Related Questions