title: Easier way to get view's Id (string) by its Id (int)
body: <p>I'm new with android and java, so sorry if it's a too basic question but I've tried to find a solution in the forums and google and I couldn't.</p>
  
  <p>I have 24 buttons in my layout, all these buttons do something similar so I want to create a generic function. But first I need to know the name (xml id) of he button.</p>
  
  <p>This the XML code of the button:</p>
  
  <pre><code>  &lt;Button
        android:id="@+id/add_04"
        android:layout_width="42dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="15dp"
        android:background="@xml/zbuttonshape"
        android:onClick="onClick"
        android:text="@string/mas" /&gt;
  </code></pre>
  
  <p>I set android:onClick="onClick" for all the buttons.</p>
  
  <p>In my activity I've create a new function onClick:</p>
  
  <p>This the code I've tried:</p>
  
  <pre><code>public void onClick(View v) {
          String name = v.getContext().getString(v.getId());
          String name2 = context.getString(v.getId());
          String name3 = getString(v.getId());
          String name4 = getResources().getString(v.getId()); 
  }
  </code></pre>
  
  <p>But when I try to get the name (in this case "add_04") I always get "false". </p>
  
  <p>Finally I've found a solution with the following code:</p>
  
  <pre><code>import java.lang.reflect.Field;
  
  String name5 = null;
  Field[] campos = R.id.class.getFields();
  for(Field f:campos){
       try{
          if(v.getId()==f.getInt(null)){
              name5 = f.getName();
              break;
          }
         }
         catch(Exception e){
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>My question is if Is not there an easier way to get this ID?</p>
  
  <p>Thanks in advance.</p>