0

Hi I tried to change the content of a textview of another xml. Unfortunaly it does not work, my code looks like this:

    View inflatedView = getLayoutInflater().inflate(R.layout.fragment_main, null);
    TextView testView= (TextView) inflatedView.findViewById(R.id.section_label);
    TextView test = (TextView) inflatedView.findViewById((R.id.testext));
    testView.setText("adasd");
    test.setText("adjhsajdH");

Does anyone know a solution.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
J.Alc
  • 1

2 Answers2

0

When you are inflating a layout, it creates a new layout. It means your first line of code does not retrieve the layout of your fragment, but creates a new one. That' why you don't see the change in your fragment view.

If you want to change the values displayed by the fragment, create a new method in which fragment that will do the job internally.

Guillaume Imbert
  • 496
  • 5
  • 11
0

try this. remove the old layout from the parent view.

parentView.removeView(urtextview)

then add the new textview u just edited

parentView.add(urTextView)
shreyas
  • 2,166
  • 3
  • 18
  • 30