views:

53

answers:

3

I've set up an onTouch class to determine when one of my 40 buttons is pressed.

The problem I am facing is determining which button was pressed.

If I use:

int ID = iv.getId();

When I click on button "widgetA1"

I receive the following ID:

2131099684

I would like it to return the string ID "widgetA1"

from:game.xml

<ImageView android:layout_margin="1dip" android:id="@+id/widgetA1" android:src="@drawable/image" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>

from:game.java

public boolean onTouch(View v, MotionEvent event) {
  ImageView iv = (ImageView)v;
  int ID = iv.getId();
  String strID = new Integer(ID).toString();
  Log.d(TAG,strID);

  //.... etc

 }

+-+-+-+-+-+-

I other wise works fine, it knows what button you are pressing. I am quite new to this Android JAVA. Let me know if you guys can help me.

A: 

What you get is an ID defined in R.id. Have a look at this post - maybe it will help

Asahi
A: 

You cannot get that widgetA1 string...You will always get an integer. But that integer is unique to that control.

so you can do this to check, which button is pressed

int ID = iv.getId();
if(ID == R.id.widgetA1) // your R file will have all your id's in the literal form.
{

}
st0le
A: 

I posted the original question, didn't set up an account so I am not sure how to reply or edit.

I could do the above, but I would need to have a giant 40+ case statement. There's no way to dynamically loop through the r.ID's?

naradlov