I have a tab bar inside my app and to maintain it I have used activity group. On clicking these tabs I have to show a set of activities. My problem is I am not able to show an alert dialog or any other dialogs inside these activities. An error occurs saying "unable to add window". Can anyone tell how to solve this issue?
It gives above error because of the Context I was providing to alertdialog builder.
Give:
new AlertDialog.Builder(getParent()).setMessage(“Hello world”).show();
We just need to call getParent() instead of AlertDialog.Builder(this)
Related
What I want to do is to show the dialog message but make it still possible to click on the items behind. On any click, the dialog would dismiss
Right now I need to click once to dismiss the dialog and a second time to click on a field.
It is something possible ? Or is there an alternative to using Dialogs?
Edit: Solution found by adding Layout Flags to the window.
In kotlin:
dialog.window?.setLayout(ConstraintLayout.LayoutParams.FLAG_NOT_FOCUSABLE, ConstraintLayout.LayoutParams.FLAG_NOT_FOCUSABLE)
By using Dialog you cannot achieve what you are looking for. instead of using Dialog USE FRAGMENT.
The examples are given in official documentation here.
You Can define a full layout in the background of the dialog and set onClick listener to that layout
I have to create customized alert in my android application. And this is my page
I have created 4 main tabs and two subtabs within my tab widget. pnr status is my first tab first page. Within that i have created customized list view. When i clicked my list view I have to show my customized alert view . I can create my customized alert. My code is here. http://pastie.org/8366400
Now my issue is When i click the list view content it shows some error my errors are http://pastie.org/8366406.
My launcher activty have four tabs. which means main actiivty. Then my first tab content is pnr status and schedule . So my pnr status will be shown first when i opened my application. But I tired some other way and found some thing. When i give my pnrstatus activity as launcher activty means my coustomized alert would shown. In the means time when i give my maintab actiivty as launcher it won't come. Now my question is If we are using tabwidget within tabwidget means our is alert won't come? Can any body help me to resolve this issue?
Use getParent() instead of context
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getParent());
refer Android dialogs are causing android.view.WindowManager$BadTokenException: Unable to add window
Try this, You can create your own xml file. setContentView this method you can set your customview.
final Dialog dialog = new Dialog(YourActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Add your lyout
dialog.setContentView(R.layout.Yourlayout);
dialog.setCancelable(true);
// Declare your view here
// Do your stuff here
dialog.show();
I want to show an Alert Dialog such that it stays on screen even if I go back to previous activity just after showing an alert dialog. Is is possible?
I tried using applicationContext but it does not work.
I don't think so, and I believe this would be a bad user experience. Perhaps you should re-think the design.
You cant do that , because a dialog is attached with a single window context , if window changes the dialog memory will be leaked and it will automatically close the dialog .You can make a same effect by showing the same dialog in both screens .However you will definitely see the transition of dialog with activity .
You can create an activity and give it a dialog theme. That way you dont have to worry about the context. It doesnt make a difference to the user also as it looks just like a dialog.
But I agree with AndyRes, It would be a bad user experience.
I have tabs that when tapped will show a view for each tab. Is it possible to create an AlertDialog that is specific to a particular view and only shows when the view is shown? So if the user taps on one tab, they would see an AlertDialog but if they tap on a different tab, the AlertDialog will not show. I don't believe its possible because I believe an AlertDialog is global within the app and when shown comes to the foreground making it impossible to tap on anything else until the dialog is dismissed. But maybe I'm wrong.
No, it is not. You may try to switch to Fragments and FragmentDialog as that would allow you to 'bind' dialog to a fragment, and each fragment can sit on separate 'tab' of your app (yet, you'd need to rework your app anyway). If you want to use 'traiditional' dialog, then you have to add a logic yourself, and not show it if different than expected tab is visible.
I have a custom AlertDialog where a user has to set password. There are two edittext views.
I compare them first if they match and if they are more than 3 characters long. If they don't match, I display a toast to alert the user. But after submitting and checking the dialog closes. How can I keep it opened until user inserts the correct values?
I was looking at doing something similar and I could not find a way do this with the standard AlertDialog as it is.
One possible way I found was to not specify any button listeners in your AlertDialog and instead place a view with your own custom buttons that perform the checks and then dismiss the dialog if necessary. I've not yet tried this to see how it works.
Another option is to create your own Custom dialog by subclassing Dialog.
You have to set a global variable like
boolean showAlert = true;
And attach a onClick listener to the AlertDialog and after cheking to see if there is need to show the alert again. If there is a need, you should show it again. You can`t keep it open if the user clicks a button from the AlertDialog. You have to recreate it again.