gpt4 book ai didi

android - 如何知道被点击的按钮 ID 是什么 - android

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:21 25 4
gpt4 key购买 nike

我在我的应用程序中创建了 3 个按钮,单击这些按钮将转到方法 giveClue。

<ImageButton
android:id="@+id/imageButton1"
android:layout_width="24dp"
android:layout_height="22dp"
android:layout_alignTop="@+id/lifeButtonsLbl"
android:layout_toLeftOf="@+id/ImageButton2"
android:src="@drawable/icon"
android:onClick="giveClue" />

<ImageButton
android:id="@+id/ImageButton2"
android:layout_width="24dp"
android:layout_height="22dp"
android:layout_alignTop="@+id/imageButton1"
android:layout_toLeftOf="@+id/ImageButton3"
android:src="@drawable/icon"
android:onClick="giveClue"/>

<ImageButton
android:id="@+id/ImageButton3"
android:layout_width="24dp"
android:layout_height="22dp"
android:layout_alignRight="@+id/frameLayout1"
android:layout_alignTop="@+id/ImageButton2"
android:src="@drawable/icon"
android:onClick="giveClue" />

注意:我不想使用不同的方法

Activity 类:

public void giveClue(View view) {
gameAdapter.giveClue(game);
}

我的问题是我想禁用被点击的按钮。我不想对每个按钮使用不同的方法。是否可以确定单击了哪个按钮,以便我可以禁用它。

谢谢。

最佳答案

检查 giveClue 方法中的 view.getId() 并将其与 R.id.imageButton1 等进行比较。通常使用 switch-case 完成 :)

关于android - 如何知道被点击的按钮 ID 是什么 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14232534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com