0
我是通过一本书学习,所以请原谅这个新手问题。Android,一堆图像按钮
我在我的xml一堆imageButtons的,这里是如何他们中的一个样子:
<ImageButton android:src="@drawable/level1" android:layout_width="wrap_content"
android:id="@+id/imageButton1" android:layout_height="wrap_content"
android:onClick="button_clicked1"></ImageButton>
和处理代码:
public void button_clicked1(View v) {
text1.setText("clicked");
}
,而不是让每个按钮都有其独立的onClick代码,无论如何,我可以通过哪个按钮被点击?例如button_clicked(1)
然后button_clicked(2)
代替button_clicked1
像它现在是(在上面的示例XML代码)
或我别无选择,只能不得不单独做呢?
是的,我也认为这是最好的选择。 –
这意味着我将不得不有一堆'((ImageButton)findViewById(R.id.imageButton1))。setOnClickListener(this);'代码,而不是吧? – Ryan
非常非常,是的。我不知道任何其他方式(例如声明式)分配处理程序。 – Brian