我曾經在一個LinearLayout中有3 ImageButton的,問題是,點擊後,「@ ID /黃」調用第二個按鈕的功能,「@ ID /綠」調用第三個按鈕功能和「@ id/brown」來調用它自己的功能(它應該是這樣做的)。的Android的ImageButton的OnClick調用相同的LinearLayout另一個函數
這裏是XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ImageButton
android:id="@+id/yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="4"
android:scaleY="2.5"
android:layout_marginLeft="13dp"
android:layout_weight="1"
android:onClick="yellowPotted"
android:background="@drawable/ball_yellow"/>
<ImageButton
android:id="@+id/green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="4"
android:scaleY="2.5"
android:layout_marginLeft="13dp"
android:layout_weight="1"
android:onClick="greenPotted"
android:background="@drawable/ball_green"/>
<ImageButton
android:id="@+id/brown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="4"
android:scaleY="2.5"
android:layout_marginLeft="13dp"
android:layout_weight="1"
android:onClick="brownPotted"
android:background="@drawable/ball_brown"/>
</LinearLayout>
這裏有我的活動3個功能(我不知道他們是否可能是有用的):
public void yellowPotted(View view) {
Log.d("BALLS", "YELLOW");
}
public void greenPotted(View view) {
Log.d("BALLS", "GREEN");
}
public void brownPotted(View view) {
Log.d("BALLS", "BROWN");
}
使用setOnClickListener()
我已經嘗試和覆蓋直接在新View.OnClickerListener()
在我的活動代碼onClick()
方法,但它不工作,要麼(完全相同的問題)。
任何人都知道可能是什麼問題?
你的問題是什麼?錯誤?崩潰? –
正如我寫的,前兩個ImageButtons調用錯誤的函數。我真的不知道什麼是錯的。 –
你的ImageButtons是否重疊? –