安卓:ImageView的的getID();返回整数 [英] Android : ImageView getID(); returning integer

查看:1013
本文介绍了安卓:ImageView的的getID();返回整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成立了一个onTouch类,以确定当我的40个按键一​​个是pressed。

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

我现在面临的问题是确定的的按钮是pressed。

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

如果我使用:

INT ID = iv.getId();

int ID = iv.getId();

当我点击按钮widgetA1

When I click on button "widgetA1"

我收到以下ID:

2131099684

2131099684

我想它返回字符串IDwidgetA1

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

来自:game.xml

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>

来自:game.java

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

 }

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

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

我其他明智的优良工程,它知道什么按钮,你是pressing。我很新的这个Android的JAVA。让我知道,如果你们能帮助我。

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.

推荐答案

您不能拿到 widgetA1 串......你总是会得到一个整数。但是,整数独有的控制。

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

所以你可以做这个检查,其中按钮pressed

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.
{

}

这篇关于安卓:ImageView的的getID();返回整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆