Foenix
Foenix

Reputation: 991

AlertDialog doesn't want to be displayed

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?

Upvotes: 0

Views: 70

Answers (3)

Ryan Sandagon
Ryan Sandagon

Reputation: 54

@Foenix, try replacing this with YourActivityName.this

e.g.

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SampleActivity.this);

Upvotes: 1

Darussian
Darussian

Reputation: 1593

You need to call

 delAllDialog.show();

Upvotes: 2

waqaslam
waqaslam

Reputation: 68177

You need to call delAllDialog.show() to display your alert dialog.

Upvotes: 2

Related Questions