Brownman Revival Brownman Revival - 3 years ago 212
Android Question

Get button ID not entire button

ArrayList<View> allButtons;
String button;
button = ((RelativeLayout) findViewById(;



System.out: [{7107785 VFED..C.. ........ 32,74-176,210 #7f0b0056 app:id/imageButton2},{c4b99da VFED..C.. ...P.... 66,256-242,352 #7f0b0057 app:id/button}]

How can i get just the id which is

Answer Source

You should write your code a s

ArrayList<View> allTouchables = ((RelativeLayout) findViewById(;
for (View view : allTouchables) {

As above code returns all touchable views present into given container, you should also check about the type of view like

ArrayList<View> allTouchables = ((RelativeLayout) findViewById(;
for (View touchable : allTouchables) {
   // To check if touchable view is button or not
    if( touchable instanceof Button) {

To get string representation of id, you can write

String idString = view.getResources().getResourceEntryName(view.getId());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download