0

Hello I need to code fast by getting a string from a certain ID's identifier.

For example the ids of my three Textviews are R.id.tv1, R.id.tv2, R.id.tv3.

I want to get a string or a char from the "tv1", basically the '1' to ease up coding and make it faster.

How do I achieve this? Getting getId() just returns an integer of the id, but I really want the string.

Thank you for your help.

  • How about managing TextViews in array with index? – SAWD Jun 05 '19 at 02:31
  • Maybe I misunderstood the question... If you meant you want to call `TextView.getText()` easier, then you first need a `TextView` instance... And you could use ButterKnife, or just use `findViewById`, but "coding faster" its all the same number of steps – OneCricketeer Jun 05 '19 at 03:18

1 Answers1

1

Actually you can create function to convert your ID's to string like

public String getCorrespondingString (int resId ) {

    switch(resId){

        case R.id.tv1: return "1";

       case R.id.tv2: return "2";

      case R.id.tv3: return "3";
    }

}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Jasurbek
  • 2,946
  • 3
  • 20
  • 37