开发者

How to dismiss Dialog on backKey Pressed!

开发者 https://www.devze.com 2023-03-10 13:53 出处:网络
Friends i have an application with an Activitiy which brings some data from Content Providers and Display it in the textViews and edittext onto the Screen. but before that it prompts me for the userna

Friends i have an application with an Activitiy which brings some data from Content Providers and Display it in the textViews and edittext onto the Screen. but before that it prompts me for the username and password in a dialog. i have done all the getting con开发者_运维知识库tent Providers Stuff in the positiveButton onClick Listener of the Alert Dialog.

It works fine but problem is that if i dont enter username and just press bakc key button it closses down the Dialog Box and the Back Screen is showed without loading the content providers.

Note: I have put my code of alert dialog in the onCreate Function of that activity.

So can u guide me how should i do it that when i press back key on dialog box it also should not display my activity.

Please Help!


your dialog name here.setCancelable(false); this is working


I would honestly just do:

mDialog.setCancelable(false); //assuming the field mDialog is your Dialog

Then make sure you have both an Okay and Cancel (Positive and Negative) buttons on your Dialog. This way, the back press will do nothing, and you can use the Cancel button to finish your activity as well if desired.


The Dialog interface provides a setCancelable() method which enables precisely this. You call that with a false value and the user won't be able to press the back button to go back to your activity.


You can use method of each activity is : onBackPressed()

http://developer.android.com/reference/android/app/Activity.html

-This is the method which you can override sub method to execute when user enter back key.

0

精彩评论

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