0

Is it possible declare many diferent TextView. Like tv_concept1, tv_concept2, tv_concept3... and so on. Using a variable string? If the string is "1" it would declare tv_concept1. So it will change the tv_concept1 text to Hi. But if the variable is it 2 then other TextView will do it.

    String textview = "tv_concept" + value;
    TextView textview = findViewById(R.id.textview);
    textview.setText("Hi");```
Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35
  • Can this link help you? https://stackoverflow.com/questions/6831506/find-view-by-name – ysys May 05 '20 at 22:16
  • yeeah!THANKS, this worked perfectly tilll the moment of setText. There is not the method for the VIEW. any idea how I could do? – Xavi Segura Ardévol May 06 '20 at 07:52
  • Which is the View method? I think you can set a string to TextView with the following code. `int value = 1; String textview = "tv_concept" + value; int id = getResources().getIdentifier(textview, "id", getPackageName()); TextView view = findViewById(id); view.setText("Hi");` – ysys May 06 '20 at 09:05
  • Thanks! Sorry I did the declaration without the ( Textview) only view = findViewById(id); This works reaaly fine now!! Doubt solved!! – Xavi Segura Ardévol May 06 '20 at 14:58

1 Answers1

0

You could use an array of your object.

shuzo
  • 83
  • 10