0

i have EditText reference set as "dimrix_1" . i have string that has value as "dimrix_1" .

how can i use the string as the reference in case i dont know the value of the string so if it will be "dimrix_2" i would like to refer to "dimrix_2" EditText and so on ...

dimrix_1 = (EditText) mRoot
        .findViewById(R.id.dimrix_et);
dimrix_2 = (EditText) mRoot
        .findViewById(R.id.dimrix2_et);
dimrix_3 = (EditText) mRoot
        .findViewById(R.id.dimrix3_et);


String ManNotNeeded = "dimrix_" + totalNumbers;

now i want go make the editText that match "ManNotNeeded" value to setVisibility(View.GONE)

hope i was clear on the explanation ...

update :

            int r = getResources().getIdentifier(
                    "edit_text_id", "id",
                    getActivity().getPackageName());
dimrix_1 = (EditText) mRoot
        .findViewById(r);

this suggest here but i don't want to use the original xml id . i want to use the reference if possible.

Jesus Dimrix
  • 4,378
  • 4
  • 28
  • 62

1 Answers1

1

The method android.content.res.Resources.getIdentifier() does what you want. For the details have a look at the documentation

Henry
  • 42,982
  • 7
  • 68
  • 84
  • i"m trying to use the reference i created before instead of original xml id . look at my edit . thanks ! – Jesus Dimrix Aug 26 '13 at 12:19
  • Sorry I don't get it. Why not using `getResources().getIdentifier( ManNotNeeded, "id", getActivity().getPackageName()); – Henry Aug 26 '13 at 12:24
  • it wont work , instead of ManNotNeeded you will need to write the view id inside the xml . otherwise r = 0 . – Jesus Dimrix Aug 26 '13 at 12:33
  • Sure, in the xml layout you need to specify static ids. Maybe rephrase your question to make clear what you need. – Henry Aug 26 '13 at 12:41