Uniquely Identify ImageButtons placed Programmatically

Posted by TiGer on Stack Overflow See other posts from Stack Overflow or by TiGer
Published on 2010-05-04T12:53:40Z Indexed on 2010/05/04 12:58 UTC
Read the original article Hit count: 250

Filed under:
|

Hi, I have been placing several ImageButtons programmatically in a TableLayout, every ImageButton has it's own Drawable resource as a Background. I use an XML description for the layout of the ImageButton itself and afterwards use the LayoutInflater to retrieve such an ImageButton (called genre_cell.xml):

<?xml version="1.0" encoding="utf-8"?>
<ImageButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/genreCellItemId" android:layout_weight="1"
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:layout_gravity="center_horizontal"
android:paddingLeft="5dip" android:paddingRight="5dip">
</ImageButton>

And in my class I do :

myButton = (ImageButton) inflater.inflate(R.layout.genre_cell, row, false);

I have actually attached an onClickListener on every ImageButton, but now I'd like to uniquely identify which ImageButton has been clicked... I thought that maybe I could somehow retrieve the Drawable's ID used for the background and check that one with the available Drawable's int values ? Is this an option and if so how should it be implemented ? Also are there any other options ?

© Stack Overflow or respective owner

Related posts about android

Related posts about imagebutton