我有一個方法deleteDilaog(它顯示對話框,yes和no選項。點擊後是它的東西,點擊時沒有它取消對話框),它要麼叫購買錄音按鈕或選擇選項菜單中的項目。問題是,結果是不一樣的?它從菜單中選擇時工作正常,但當點擊一個按鈕時,它只是顯示對話框,不管我點擊什麼,什麼都沒有發生?onButtonClick與onMenuItemSelected -----不一樣的結果
按鈕:
private void RemoveAll(){
Button button=(Button) findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteDialog();
}
});
}
菜單項:
@Override
public boolean onMenuItemSelected(int id, MenuItem item) {
mDeleteId=item.getItemId();
switch(item.getItemId()) {
case INSERT_ID:
addItem();
return true;
case DELETE_ALL_ID:
deleteDialog();
break;
}
return super.onMenuItemSelected(id, item);
}
deleteDialog方法:
private void deleteDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage
(CONFIRM_DIALOG_STRING).setCancelable(false).setPositiveButton
(POSITIVE, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int
which) {
switch (mDeleteId) {
case DELETE_ALL_ID:
mDbHelper.removeAllLists();
fillData();
break;
case DELETE_ID:
Cursor c = (Cursor)
getListView().getAdapter().getItem(which);
mDbHelper.removeList
(mItemId);
c.requery();
break;
}
}
}).setNegativeButton(NEGATIVE, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int
which) {
dialog.cancel();
}
});
AlertDialog alertDialog = dialog.create();
alertDialog.show();
}
使用dialog.dismiss()代替dialog.cancel() – Enigma 2012-02-14 10:23:09
編號相同的結果,工作槽菜單,不使用按鈕 – pedja 2012-02-14 10:56:55