ImageButton-如何读取图像ID?
对不起,这个问题的问题,但我是Android的新手。我有一个问题。我有几个imageButton元素,我需要根据OnClick()事件中的内容来更改它们的图像。虽然设置新图像不是问题,但我无法编程地读取当前的图像(下一个图像取决于它)。我搜索各种来源并且找不到解决方案。当然很简单。
我想拥有这样的代码:
if (ImageButton1.image... == R.drawable.img1)
{
ImageButton1.setImageResource(R.drawable.img2)
ImageButton2.setImageResource(R.drawable.img3)
...
}
任何帮助。谢谢...
Sorry for the banal question, but I'm new to Android. I have such a problem. I have several ImageButton elements and I need to change their images depending on what is on them during onClick() event. While setting a new image is not a problem, I can not programmatically read what image is currently (the next image depends on it).I search various sources and can't find a solution. It is certainly very simple.
I want to have a code like this:
if (ImageButton1.image... == R.drawable.img1)
{
ImageButton1.setImageResource(R.drawable.img2)
ImageButton2.setImageResource(R.drawable.img3)
...
}
Any help appreciated. Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决此问题的一种方法是有一个int数组,并以格式存储在
中
数组
One approach to get over this is have an Int array and store the drawables in the array in the format
Now set the images as ImageButton1.setImageResource(listOfImages(0))
That way you know which drawablr is being used