這是我的佈局:的Android的ImageButton不工作
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white" >
<ImageButton
android:id="@+id/one_button"
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/1"
android:contentDescription="@string/by1" />
<ImageButton
android:id="@+id/two_button"
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/2"
android:contentDescription="@string/by2" />
<ImageButton
android:id="@+id/three_button"
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="185dp"
android:background="@drawable/3"
android:contentDescription="@string/by3" />
<ImageButton
android:id="@+id/four_button"
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginTop="185dp"
android:background="@drawable/4"
android:contentDescription="@string/by4" />
</RelativeLayout>
這是我的代碼:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.one_button :
startActivity(new Intent("android.intent.action.GROUP"));
break;
case R.id.two_button :
startActivity(new Intent("android.intent.action.ATOZ"));
break;
case R.id.three_button :
startActivity(new Intent("android.intent.action.ATOZ"));
break;
default :
break;
}
}
現在,如果我按one_button
或two_button
所有的作品如預期,但如果我按three_button
什麼發生。
我在做什麼錯?
P.S. - 清單是好的,因爲two_button
開始所需的活動。
感謝,
favolas
我很驚訝地看到,你的第2個按鈕甚至工作,這應該拋出編譯錯誤,因爲按鈕ID不能以數字開頭。 – Sudhaker 2012-07-27 11:16:28
這僅僅是一個例子。編輯我的問題。沒有收到編譯器錯誤,甚至沒有警告 – Favolas 2012-07-27 11:18:31
你有沒有爲onClickListener分配第三個按鈕? – 2012-07-27 11:20:37