title: get index and id of selected edittext for further processing
body: <p>New to android and programming in general, so learning concepts as I go.</p>
  
  <p>I have a LinearLayout to which I am adding edittexts dynamically.</p>
  
  <p>I need to be able to get the Index AND Id of any edittext when it is selected or in focus.</p>
  
  <p>I have tried looping through a child count to check for selected like so:</p>
  
  <pre><code>int count = llmain.getChildCount();
        for (int i=0; i&lt; count; ++i) {
            if ((llmain.getChildAt(i).isSelected()) == true){
              //Do Stuff
            }
  </code></pre>
  
  <p>but I have no idea if its even close, and that would be only for index.....</p>
  
  <p>Help would be greatly appreciated!</p>
  
  <p>Thanks</p>
  
  <p>EDIT: still dont have a reliable way to achieve this. The example below with the</p>
  
  <pre><code>if(v instanceOf EditText) {
  id = v.getId();
  index = ll.indexOfChild(v);
  </code></pre>
  
  <p>returns a -1 for index and a ten digit number for the id, however, i am assigning an id on creation. ?The odd thing is that the code inside the "if" is running, so it at least thinks it has the focused view. Now, if I change the "instanceof" to a null check like</p>
  
  <pre><code>if (v != null){
              id = v.getId();
              index = llmain.indexOfChild(v);
  </code></pre>
  
  <p>AND I add a setFocusableInTouchMode(true), I get a proper return, however, it then acts like i called clearFocus(), because none of the EditTexts are focused. Here is my full proof of concept code that returns the correct values but no longer lets the EditTexts actually have focus.</p>
  
  <pre><code>@Override
  public boolean dispatchKeyEvent(KeyEvent event) {
  
      if ((event.getAction() == KeyEvent.ACTION_DOWN) &amp;&amp;(event.getKeyCode() == 66)) // KeyEvent.* lists all the key codes u pressed
      {   
          View myView = linflater.inflate(R.layout.action, null);
          myView.setId(pos);
          pos++;
          myView.setFocusableInTouchMode(true);
          llmain.addView(myView);
          myView.requestFocus();
          View v = llmain.findFocus();
  
          if (v != null){
              id = v.getId();
              index = llmain.indexOfChild(v);
              Context context = getApplicationContext();
              CharSequence text = "index is:" + index + "id is:" + id;
              int duration = Toast.LENGTH_SHORT;
  
              Toast toast = Toast.makeText(context, text, duration);
              toast.show();
              }
  
  
      }
      return false;   
  }       
  </code></pre>
  
  <p>This returns the correct values unless I comment the setFocusableInTouchMode line, then it goes back to the odd -1 for index and ten digit for ID.   What am I doing wrong? going to have to be a good (and working) answer to get over half of my rep.....   </p>
  
  <p>So nobody has a solution for this? its still driving me nuts! </p>
  
  <p>thanks again</p>