我有一個簡單的應用程序與2 buttoms,它會觸發通知。後來編程的進度我想改變正常的buttoms爲圖像buttoms,因爲更好的設計,所以我刪除了正常的buttoms和但圖像buttoms和改變了id回到原來的 buttom1和buttom2,,但現在它不再工作。我做錯了什麼?我必須編程圖像buttoms不同於正常的?我是否必須安裝libarys或somthing?請幫我!操作不再適用於圖像按鈕?
XML:
<ImageButton
android:id="@+id/buttom2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/buttom1"
android:layout_below="@+id/buttom1"
android:layout_marginTop="23dp"
android:src="@drawable/icon2" />
<ImageButton
android:id="@+id/buttom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="14dp"
android:src="@drawable/icon1" />
main.java:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sendNotification(View view) {
switch(view.getId()){
case R.id.buttom1:
Notification1();
break;
case R.id.buttom2:
Notification2();
break;
}
}
private void Notification1() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setContentTitle("BasicNotification");
builder.setContentText("Test");
builder.setSmallIcon(R.drawable.icon1);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
manager.notify((int) System.currentTimeMillis(), notification);
}
private void Notification2() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setContentTitle("BasicNotification");
builder.setContentText("Test");
builder.setSmallIcon(R.drawable.icon2);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
manager.notify((int) System.currentTimeMillis(), notification);
}
}
感謝前面!
添加一些XML ??? – Olayinka 2014-09-04 22:37:59
好吧我編輯它 – DudeEffects 2014-09-04 22:43:49
告訴我你在哪裏定義的按鈕,請 – 2014-09-04 22:47:36