0

I have good working code when I asked the user to delete item ot not.

case R.id.item_Delete:
        Log.d("TAG","Deletion ...");
        AlertDialog.Builder delAllDialog = new AlertDialog.Builder(this);
        delAllDialog.setTitle("Confirm deletion");
        TextView dialogTxt_id = new TextView(this);
        LayoutParams dialogTxt_idLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        dialogTxt_id.setLayoutParams(dialogTxt_idLayoutParams);
        dialogTxt_id.setText("Delete?");
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.addView(dialogTxt_id); 
        delAllDialog.setView(layout);
        delAllDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                delete();
            }
        });
        break; 
...

It works great! I just copy this peace of code and place it to another similar activity in right the same menu code. And I have got Deletion.. in my log and then nothing happened. LogCat it clear, no errors.

I search and find several other same questions (for example Android - AlertDialog doesn't show when called from Main-Method ) but nor cleaning the project nor other things doesn't solve my problem.. Any ideas?

4

3 回答 3

2

您需要调用delAllDialog.show()以显示警报对话框。

于 2013-03-21T20:54:34.147 回答
2

你需要打电话

 delAllDialog.show();
于 2013-03-21T20:55:05.697 回答
1

@Foenix,尝试替换thisYourActivityName.this

例如

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SampleActivity.this);
于 2013-03-21T20:37:59.983 回答