AlertDialog - how can I run checks when user hits 'OK'

后端 未结 4 1802
鱼传尺愫
鱼传尺愫 2021-01-13 14:46

For a custom AlertDialog, can I override the positive button to NOT close the dialog? instead I want to run some edit checks and keep the dialog open if my checks fail.

4条回答
  •  北海茫月
    2021-01-13 14:47

    Ok, here is just an idea of how it is possible to implement.

    AlertDialog.Builder has setView(View v) method. So it is possible to add, say, a custom LinearLayout (inflated from resources right before Dialog building) with button(s). Then just set usual android.view.View.OnClickListener(s) on the button(s). In this case don't use those "built-in/native" for the AlertDialog.Builder buttons at all.

提交回复
热议问题