Display Android dialog on top of another?

后端 未结 4 966
离开以前
离开以前 2020-12-19 07:46

I have 2 alert dialogs, dialog A and dialog B. Clicking on one of dialog A\'s buttons will bring up dialog B. I then want to have a button that will dismiss dialog B and ret

相关标签:
4条回答
  • dismiss the dialog from within itself.

    Edit, here is some clearer code.

        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                return;
            }
        });
        alertDialog.show();
    
    0 讨论(0)
  • 2020-12-19 08:25

    Using the basic dialog building blocks it is not possible to have them stack, you will need to re-show the first dialog. The reason for this is that when you press a dialog button it internally will dismiss the dialog as part of the process for calling the click handler you assigned for each button in the dialog builder API.

    One way around this is to make a custom dialog layout that doesn't have the dismiss behavior, by setting up your own buttons in the layout, rather than using those created by the dialog builder methods. Then in the click handler for you own buttons simply show the second dialog without dismissing the first. http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

    0 讨论(0)
  • 2020-12-19 08:30

    As one reply mentioned, you cannot do this with standard dialogs. But you can do it by making the first dialog be an activity that is styled to look like a dialog, and the second is actually a dialog. Just set the theme of the activity in your layout like so:

    <activity android:theme="@android:style/Theme.Dialog">
    

    See this topic on making an activity that looks like a dialog. https://stackoverflow.com/a/1979631/602661

    0 讨论(0)
  • 2020-12-19 08:37

    You should use inside your custom layout one view/button and based on this view/button click you can create another dailog without cancel first one, if you use builder.setNegativeButton or builder.setPositiveButton your current dialog will be close, my working code like as,

    AlertDialog.Builder builder = new AlertDialog.Builder(ActivityAppImages.this,R.style.your_style);
    LayoutInflater inflater = getLayoutInflater();    
    View dialoglayout = inflater.inflate(R.layout.your_custom_layout, null);
    
    final Button mButtonCreateOtherDailog = (Button)dialoglayout.findViewById(R.id.txt_create_second_dailog);
        mTextView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //create your other dailog here
            }
        });
    
    builder.setView(dialoglayout);
    builder.show();
    
    0 讨论(0)
提交回复
热议问题