Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could do this via reflection as Quoi points out, but this is generally not a good a idea.</p> <p>It would be better just to add your objects to a list or a map:</p> <pre><code>List&lt;EditText&gt; list = new ArrayList&lt;EditText&gt;(); EditText editTxt1 = (EditText) findViewById(R.id.editText1); list.add(editTxt1); EditText editTxt2 = (EditText) findViewById(R.id.editText2); list.add(editTxt2); EditText editTxt3 = (EditText) findViewById(R.id.editText3); list.add(editTxt1); EditText editTxt4 = (EditText) findViewById(R.id.editText4); </code></pre> <p>Now we can cycle through the list and use the index to check which edit text was being called.</p> <pre><code>int i = 0; for (EditText e : list) { if(e.getText().toString().equals("something")) { System.out.println("editText" + i + " equals something"); // do stuff } i++; } </code></pre> <p>You could also use a Map to do this, this would allow you to have a name value against your objects to help give you a better reference to check what object was being called. This takes a bit more work, but might be use</p> <pre><code>Map&lt;EditText, String&gt; map = new HashMap&lt;EditText, String&gt;(); EditText editTxt1 = (EditText) findViewById(R.id.editText1); map.put(editTxt1, "editTxt1"); EditText editTxt2 = (EditText) findViewById(R.id.editText2); list.add(editTxt2, "editTxt2"); for (Entry&lt;String, String&gt; e : map.entrySet()) { if(e.getValue().equals("something")) { System.out.println(e.getKey() + " was equal to somethihng"); } } </code></pre> <p><a href="https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java">PS - Never use <code>==</code> to compare Strings, it won't always work!!</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload