0

This is my Fragment class and I have a textView in xmlfile

How can I change the TextView by setText?

public class Frist extends Fragment   {

    TextView text;

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

        View rootView = inflater.inflate(R.layout.activity_frist, container, false);
        TextView t = (TextView) this.getView().findViewById(R.id.textView1);
        t.setText("SOME TEXT");

        return rootView;

    }
}
galath
  • 5,717
  • 10
  • 29
  • 41

1 Answers1

2

Instead of

TextView t = (TextView) this.getView().findViewById(R.id.textView1);

You should be calling findViewById on the view you inflate:

TextView t = (TextView) rootView.findViewById(R.id.textView1);
HexAndBugs
  • 5,549
  • 2
  • 27
  • 36