开发者

Prevent dismissing an AlertDialog.Builder until a condition is satisfied

开发者 https://www.devze.com 2023-01-29 03:18 出处:网络
I have an AlertDialog.Builder with an OK button, a Cancel button, and an EditText.I wa开发者_运维知识库nt to prevent the user from hitting \"OK\" and dismissing the dialog until they actually type som

I have an AlertDialog.Builder with an OK button, a Cancel button, and an EditText. I wa开发者_运维知识库nt to prevent the user from hitting "OK" and dismissing the dialog until they actually type something in the EditText.

The dialog seems to automatically dismiss itself when either button is pressed. Is there a way I can grey/disable the OK button until I meet a condition?

I'm thinking I will have to implement a custom dialog to accomplish this. Anyone have any ideas? Thanks!


I ended up scratching the alert dialog in favor of another activity.

I used a dialog themed activity in the manifest to give me the dialog box appearance, put my views in an XML layout and then just manually coded the Views for the functionality I wanted.


You can try creating a activityForResult which looks like a Dialog Box and floats on the top of previous Activity. There you can disable the buttons until the EditText is filled.


i just went over the builder. Since it seems like the builder dosn't give you access to the layout itself it might be problematic... You can always inherit AlertDialog and set your own buttons and behaviour, what you want to do is use a simple layout with two buttons and textEdit, have a TextWatcher over the text edit so when the txtedit is not length of 0 the ok button is diabled and have the dialog with cancelable=false.

0

精彩评论

暂无评论...
验证码 换一张
取 消