【问题标题】:How to search the id of imagebuttons?如何搜索图像按钮的 id?
【发布时间】:2017-11-27 20:49:21
【问题描述】:

我创建了很多图像按钮,我想在同一个活动中搜索它们。

我不知道如何搜索图像按钮 ID。
或者有什么其他的方法吗?

【问题讨论】:

  • 创建一个 ArrayList 并在创建 ImageButtons 时将它们添加到列表中。

标签: android search imagebutton


【解决方案1】:

你应该使用findViewById方法:

ImageButton button1 = (ImageButton) findViewById(R.id.button1);

你应该在你的xml文件中设置id:

android:id="@+id/button1"

或者,如果您以编程方式创建ImageButtons,您可以这样做:

button1 = new ImageButton(activity);
button1.setId("button1");

稍后再使用findViewById

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多