You are different to most teachers on RUclips. And that is a good thing. People teaching how to do stuff often forget to explain why they are writing this piece of code, you explain it all. AND It's great. I've subscribed + thanks!
Thank you soo much! I spent long long time trying to understand why I couldnt access my views without relating them into the inflate Layout using mView ! And then Bingo, finally I found your video and you helped me a lot with this!
Hello@@walidpivano117 , in this case I would ask myself the following: 1.Did I really create a view in my XML popup file? Did I give it an id? Did I call it as said in the video by using the ".view" before the findViewById(ex TextView textView = view.findViewById(R.id.myTextViewId); Did I set the view with alertDialog method setView? example: alertDialog.setView(view); Finally did I type alertDialog.show()? I hope my own questions can help you to resolve your 'null object reference'. Good luck!
Great video! Just one question. I changed the font on my edit texts from the custom dialog layout, but I want to change the font of the dialog title and the positive/negative buttons. Is there a way to do that? Also I would like to create a radius for the dialog box! Thank you
To dismiss the dialog you just call dialog.dimiss(). For example if you want to dismiss the dialog when the user have successfully filled email, password field and clicks on "Login button" you do it like this: - First you show the dialog like this: final AlertDialog dialog = mBuilder.create(); dialog.show(); - Then you call setOnClicklistener for the login button like this: mLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(!mEmail.getText().toString().isEmpty() && !mPassword.getText().toString().isEmpty()){ Toast.makeText(MainActivity.this, R.string.success_login_msg, Toast.LENGTH_SHORT).show(); dialog.dismiss(); }else{ Toast.makeText(MainActivity.this, R.string.error_login_msg, Toast.LENGTH_SHORT).show(); } } }); Happy coding :)
Thanks very much for the great tutorial. I still wonder how I can wait for the dialog to be dismissed and then access and use the input for Email and Password? That would help me a lot!
Hi, if i understand your question correctly the dialog will not be dismissed unless you actually write the code for it. For example you can dismiss the dialog when the user have successfully entered the email and password then you call dialog.dismiss() Based on the example provided in the video you can call dialog.dismiss after the successful login toast message which will hide the dialog. I hope that answered your question :)
Sorry, my question was not precise enough. The functionality you describe works fine and the dialog is properly dismissed. But AFTER dismissing the dialog I need to use the input from within the dialog in the "calling program". Problem 1: the calling program doesn't wait for user input and dismissal Problem 2: i can't get the email/password-input out of the inner onClick-method and pass it to the calling program my current code: (...) String password; Button mShowDialog = (Button) findViewById(R.id.btnShowDialog); mShowDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this); View mView = getLayoutInflater().inflate(R.layout.dialog_login,null); final EditText mEmail = (EditText) mView.findViewById(R.id.etEmail); final EditText mPassword = (EditText) mView.findViewById(R.id.etPassword); Button mLogin = (Button) mView.findViewById(R.id.btnLogin); mBuilder.setView(mView); final AlertDialog dialog = mBuilder.create(); dialog.show(); mLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mEmail.getText().toString().isEmpty() && !mPassword.getText().toString().isEmpty()) { Toast.makeText(MainActivity.this, R.string.success_login_msg, Toast.LENGTH_SHORT).show(); dialog.dismiss(); } else { Toast.makeText(MainActivity.this, R.string.error_login_msg, Toast.LENGTH_SHORT).show(); } } }); password = mPassword.getText().toString(); } }); Toast.makeText(MainActivity.this,"Passwort ist "+password, Toast.LENGTH_SHORT).show(); The Toast-Command displays right at startup of the app, even before the alert diaglog is created. This code doesn't even compile because any variable (like password) from within the inner onClick method isn't visible in the last line of code or it is not accessible in the onClick method. Help!
When you add the dialog.dismiss() an error happens saying that it can not resolve symbol. I am having the same issue as A. Meier where after everything is successfully done, I am not sure as to how close the dialog. If you could elaborate on what you said you give some insight on how to solve this problem that would be great.
Hello sir. i had a query. If i wanted the button on the dialog to redirect me to a different page how do i implement it? For example if i had a modify button on the dialog which takes me to a different page, how will it work?
Hi, inside mLogin onClick method you add the following code: startActivity(new Intent(MainActivity.this, NewActivity.class)); Note: (NewActivity.class) is the page that you want to send the user to.
Right Way Entertainment Ajay Sajeev declare the Alert Dialog as a Global Variable and inside the onClickListener type the name of the global Variable and put the cancel button // Global Variable AlertDialog ad; ........ onClick{ ad.cancel } You surely need to look up at Stack overflow....Even I checked it.
I have created a dialog like this , but at onClickListener method I have a variable that its value is changing and it giving me an error saying "Variable is accessed within inner class. Needs to be declared final" I can't declare it final because its value is changing what should I do please?
Hi, in that case you can declare that variable on top not inside any inner method, so that you can reference that variable without declaring it as final
I want to go to another activity click on a button on the dialog box. I am trying but not able to move it there I think because it is layout resource file. I just want to work with this dialog box work on click event. please help me.
Hi, you don't have to make any changes in the layout resource file, based on the video there is a login button so let's say you want to go to another activity whenever the user taps on the button, you can do it like this: Inside the mLogin.setOnClickListener method replace the the toast message with the following line: startActivity(new Intent(MainActivity.this, NewActivity.class)); Now when the user taps on the login button it will send the user to another page. I hope that helps :)
First you need to show the alertdialog and then call button setOnClickListener to make the button clickable. Inside the OnClick method is where you will dismiss the dialog like this: final AlertDialog dialog = mBuilder.create(); dialog.show(); mLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(!mEmail.getText().toString().isEmpty() && !mPassword.getText().toString().isEmpty()){ Toast.makeText(MainActivity.this, R.string.success_login_msg, Toast.LENGTH_SHORT).show(); dialog.dismiss(); }else{ Toast.makeText(MainActivity.this, R.string.error_login_msg, Toast.LENGTH_SHORT).show(); } } });
Hi, create a button inside the dialog_login.xml file and you can place it under the login button, then declare the cancel button inside alertdialog like i did for the login button. Inside the cancel button's onClick method you can dismiss the dialog like this: final AlertDialog dialog = mBuilder.create(); dialog.show(); mCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } });
My biggest complaint with this video is that it does not show you any useful use case for the button. For example, how do you get the login button to close the dialog on success? (Showing a toast is pretty useless imo), How do I get and set the values of these editTexts? Though it's just a case of accessing their variables it would make this video complete
I got it to work define AlertDialog dialog as final. "final AlertDialog dialog = mBuilder.create();" Then you can call dismiss(). Like someone answered here: stackoverflow.com/questions/49349668/how-to-dismiss-custom-alert-dialog
Hi, you can access the source code at this link: github.com/codingdemos/CustomAlertDialogTutorial Please let me know if you need any help with the code above
can you please make a tutorial on how to enable pop ups by default for web app. because my website need pop ups enable to open after login. i already make app for that website but after login it shows nothing not even pop ups notification.
Any text inputed into the Editext shows up as null. AlertDialog.Builder mBuilder = new AlertDialog.Builder(HomePage.this); View mView = LayoutInflater.from(HomePage.this).inflate(R.layout.dialog_new_post, null); //does not work when u try to do it the way u have it in your video EditText etNewPostDialog = (EditText) mView.findViewById(R.id.etNewPostDialog); Button btnCreatePostDialog = (Button) mView.findViewById(R.id.btnNewPostDialog); final String newPostDialog = etNewPostDialog.getText().toString().trim(); final String username = SharedPrefManager.getInstance(this).getUsername(); // final String post = etNewPostDialog.getText().toString(); btnCreatePostDialog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //sendUserPost(username); Toast.makeText(HomePage.this, newPostDialog, Toast.LENGTH_SHORT).show(); } }); mBuilder.setView(mView); AlertDialog dialog = mBuilder.create(); dialog.show(); } So far every way I have tried it has returned null. Also side question how would you close the dialog. Thanks for the help thus far tho
Hi, do you get any error in the logcat when you try to insert a value in the edittext? and may i know why this line doesn't work (View mView = getLayoutInflater().inflate(R.layout.dialog_login, null);) do you get any errors? You can email me (codingdemos@gmail.com) your project code and i'll do my best to help you :)
Appreciate the response, I figured it out, I went about it a bit differently then your video, but still got the correct end result. This is what I did to fix it. Thanks again for the video. Actually helped a lot. public void displayDialog(){ LayoutInflater layoutInflater = LayoutInflater.from(this); final View inflator = layoutInflater.inflate(R.layout.dialog_new_post, null); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Title"); final EditText etNewDialogPost = (EditText) inflator.findViewById(R.id.etNewPostDialog); alert.setPositiveButton("ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { final String etNewPostDialog = etNewDialogPost.getText().toString().trim(); //do something } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.cancel(); } }); alert.show(); }
Hi, all you have to do is follow the tutorial that i did which will teach you how to create the option menu, and then you can use this alertdialog code together to show the dialog every time you click on any items in the option menus. Here is the video tutorial link: ruclips.net/video/EZ-sNN7UWFU/видео.html
Ajay Sajeev declare the Alert Dialog as a Global Variable and inside the onClickListener type the name of the global Variable and put the cancel button // Global Variable AlertDialog ad; ........ onClick{ ad.cancel } You surely need to look up at Stack overflow....Even I checked it.
You are different to most teachers on RUclips. And that is a good thing.
People teaching how to do stuff often forget to explain why they are writing this piece of code, you explain it all. AND It's great.
I've subscribed + thanks!
Hi Thomas, thanks a lot for the kind words...i'm really happy that you found my videos helpful
Thanks for watching and subscribing :)
Thank you soo much! I spent long long time trying to understand why I couldnt access my views without relating them into the inflate Layout using mView ! And then Bingo, finally I found your video and you helped me a lot with this!
I meet an error in this example
attempt to invok oncllikListener on a null obect refrence
Hello@@walidpivano117 , in this case I would ask myself the following: 1.Did I really create a view in my XML popup file? Did I give it an id? Did I call it as said in the video by using the ".view" before the findViewById(ex TextView textView = view.findViewById(R.id.myTextViewId); Did I set the view with alertDialog method setView? example: alertDialog.setView(view); Finally did I type alertDialog.show()? I hope my own questions can help you to resolve your 'null object reference'. Good luck!
Ohhh thanks man
Because of you I find my error thats was so helpful i forgot v.find...
Thanks you 💪❤
maaaaaa negga. You're like Jesus to me right now. You don't know how much this has been helpful. Thanks!
Awesome i'm glad you found it helpful :)
Thank you so much! This tutorial was very intuitive, easy to follow, and easily applied to other situations. I used it with a ListView.
Great explaining and good example. Great job! I feel like am watching paid content.
Thanks, I don't understand your language but it helped me a lot.
I wanted to hit 1k likes but Unfortunately i only had thumb up
Thankyou and that one was amazing helpful nd easiest explained video
hahaha..Thanks for watching :)
Thanks a lot. Respect from Mexico.
WAWWW this tutorial os soooo good. Thanks a lot, i was lokking for exactly this tutorial
Cool, i'm glad to hear that :)
Danke Lieber GOTT.... greetings from germany
Awesome job dude! You explain very well
i really love your tutorials easy to learn . thanks for this :)
Really an awesome explaination,w want more tutorial from you, thanks
I know this is an old video but great tutorial!
Thanks sir that was clear and helpful tutorial
terima kasih. penerangan yang amat bagus sekali.
Great tutorial ...... Thanks my friend
Thanks! this one is very helpful. and you just got one new subscriber :)
This worked wonderfully. Thanks!
Thank you very much, very good explanation!
Thanks for watching :)
amazing thanks! Greetings from Mexico
Thank you this is easy than I expected
Thanks for watching :)
how to dismiss after login button clicked because there is not any method to dismiss that dialog???
Thanks for this. great job, man
nice ty ,, just what i needed ,,
you explain very well
Thanks for watching :)
Great video!
Just one question. I changed the font on my edit texts from the custom dialog layout, but I want to change the font of the dialog title and the positive/negative buttons. Is there a way to do that? Also I would like to create a radius for the dialog box!
Thank you
Thank you very much, great tutorial!.
How to controller disapper buttons in rotation lanscape.
Thank you for this tutorial, it really helped me out.
Thank you so much for this amazing video...
#Subscribed :)
Thanks for watching and subscribing to the channel :D
You're most welcome ^_^
amazing man.... Hats off....
Thanks for the video, very usefull :)
Thanks for watching :)
Thanks A LOT !! You saved me with this!
Ajudou muito, muito obrigado pela explicação simples e efetiva, me inscrevi no canal para acompanhar as novidades.
Gracias, me fue de mucha ayuda.
Your welcome :)
Nicely done!
You could use preview rather than going to design view every time to check the design.
Cool thanks for pointing that out :) i'll use it next time
Thank you very much.
Instantly Subscribed :)
Thanks a lot.. very helpfull..
Merci pour ce petit tuto.
Your welcome :)
Thanks a lot. Your explanation is so great.
Just one doubt, how can I dismiss this dialog, please?
To dismiss the dialog you just call dialog.dimiss(). For example if you want to dismiss the dialog when the user have successfully filled email, password field and clicks on "Login button" you do it like this:
- First you show the dialog like this:
final AlertDialog dialog = mBuilder.create();
dialog.show();
- Then you call setOnClicklistener for the login button like this:
mLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!mEmail.getText().toString().isEmpty() && !mPassword.getText().toString().isEmpty()){
Toast.makeText(MainActivity.this,
R.string.success_login_msg,
Toast.LENGTH_SHORT).show();
dialog.dismiss();
}else{
Toast.makeText(MainActivity.this,
R.string.error_login_msg,
Toast.LENGTH_SHORT).show();
}
}
});
Happy coding :)
Coding Demos Tks só much, man ;)
did it work for you
Thank you very much, great tutorial!
big thank man, this really work for me
That's awesome, happy coding :D
hey bro, awesome work,
but I have a question how to dismiss like in the normal dialog video.
I have done it, just make the dialog object global and dismiss it from inside the log in button handler.
That's awesome :)
what was your code to do that?
This was awesome .. Thanks a lot.
gracias. . como hago al final despues de presionar el boton login desaparezca el layout creado??
great tutorial! thanks
Excellent Tutorial!.. Thanks! .
Subscribed!
Your welcome, happy coding :)
Thanks very much for the great tutorial. I still wonder how I can wait
for the dialog to be dismissed and then access and use the input for
Email and Password? That would help me a lot!
Hi, if i understand your question correctly the dialog will not be dismissed unless you actually write the code for it.
For example you can dismiss the dialog when the user have successfully entered the email and password then you call dialog.dismiss()
Based on the example provided in the video you can call dialog.dismiss after the successful login toast message which will hide the dialog.
I hope that answered your question :)
Sorry, my question was not precise enough. The functionality you describe works fine and the dialog is properly dismissed. But AFTER dismissing the dialog I need to use the input from within the dialog in the "calling program".
Problem 1: the calling program doesn't wait for user input and dismissal
Problem 2: i can't get the email/password-input out of the inner onClick-method and pass it to the calling program
my current code:
(...)
String password;
Button mShowDialog = (Button) findViewById(R.id.btnShowDialog);
mShowDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
View mView = getLayoutInflater().inflate(R.layout.dialog_login,null);
final EditText mEmail = (EditText) mView.findViewById(R.id.etEmail);
final EditText mPassword = (EditText) mView.findViewById(R.id.etPassword);
Button mLogin = (Button) mView.findViewById(R.id.btnLogin);
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
dialog.show();
mLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mEmail.getText().toString().isEmpty() &&
!mPassword.getText().toString().isEmpty()) {
Toast.makeText(MainActivity.this, R.string.success_login_msg, Toast.LENGTH_SHORT).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this, R.string.error_login_msg, Toast.LENGTH_SHORT).show();
}
}
});
password = mPassword.getText().toString();
}
});
Toast.makeText(MainActivity.this,"Passwort ist "+password, Toast.LENGTH_SHORT).show();
The Toast-Command displays right at startup of the app, even before the alert
diaglog is created. This code doesn't even compile because any variable
(like password) from within the inner onClick method isn't visible in the
last line of code or it is not accessible in the onClick method.
Help!
hi did you ever figure it out
When you add the dialog.dismiss() an error happens saying that it can not resolve symbol. I am having the same issue as A. Meier where after everything is successfully done, I am not sure as to how close the dialog. If you could elaborate on what you said you give some insight on how to solve this problem that would be great.
very helpful! thanks!
Amazing video!!
awesome video!
thanks you very much
thank you very much , this video is usefull
Your welcome :)
Hello sir. i had a query. If i wanted the button on the dialog to redirect me to a different page how do i implement it? For example if i had a modify button on the dialog which takes me to a different page, how will it work?
Hi, inside mLogin onClick method you add the following code:
startActivity(new Intent(MainActivity.this, NewActivity.class));
Note: (NewActivity.class) is the page that you want to send the user to.
this is a great tutorial the only thing i wish you would show is how to close the alertdialog after successful login
Right Way Entertainment Ajay Sajeev declare the Alert Dialog as a Global Variable and inside the onClickListener type the name of the global Variable and put the cancel button
// Global Variable
AlertDialog ad;
........
onClick{
ad.cancel
}
You surely need to look up at Stack overflow....Even I checked it.
key statement
- getLayoutinflater
- mBuilder.setView(mView)
- dialog = mBuilder.create();
- dialog.show()
can i add recyclerview in dialog
or what is the best way to put recyclerview in popup
Thanks a lot.
I have created a dialog like this , but at onClickListener method I have a variable that its value is changing and it giving me an error saying "Variable is accessed within inner class. Needs to be declared final"
I can't declare it final because its value is changing
what should I do please?
Hi, in that case you can declare that variable on top not inside any inner method, so that you can reference that variable without declaring it as final
How do I close a dialog box after clicking on the button?
this.getDialog().cancel();
I want to go to another activity click on a button on the dialog box. I am trying but not able to move it there I think because it is layout resource file. I just want to work with this dialog box work on click event. please help me.
Hi, you don't have to make any changes in the layout resource file, based on the video there is a login button so let's say you want to go to another activity whenever the user taps on the button, you can do it like this:
Inside the mLogin.setOnClickListener method replace the the toast message with the following line: startActivity(new Intent(MainActivity.this, NewActivity.class));
Now when the user taps on the login button it will send the user to another page.
I hope that helps :)
Perfect! Thank you!
Your welcome :)
Hey I have a problem!
When I click edittext the keyboard doesn't show the input doesn't work .
Hi, hmm that's strange! Do you see any errors in logcat? You can email me (codingdemos@gmail.com) the source code so that i can see what is the issue
Coding Demos Thanks For This Tutorial it Helped Me A lot .Anyway how can I close this dialog using a button? Coz the dismiss doesn't work !
First you need to show the alertdialog and then call button setOnClickListener to make the button clickable. Inside the OnClick method is where you will dismiss the dialog like this:
final AlertDialog dialog = mBuilder.create();
dialog.show();
mLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!mEmail.getText().toString().isEmpty() && !mPassword.getText().toString().isEmpty()){
Toast.makeText(MainActivity.this,
R.string.success_login_msg,
Toast.LENGTH_SHORT).show();
dialog.dismiss();
}else{
Toast.makeText(MainActivity.this,
R.string.error_login_msg,
Toast.LENGTH_SHORT).show();
}
}
});
Thanks Man ! I subscribed !!!!
Your welcome and thanks for subscribing :)
How to add also cancel button in this custom dialog?
Hi, create a button inside the dialog_login.xml file and you can place it under the login button, then declare the cancel button inside alertdialog like i did for the login button. Inside the cancel button's onClick method you can dismiss the dialog like this:
final AlertDialog dialog = mBuilder.create();
dialog.show();
mCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
Thanks
Your welcome :)
Thanks a lot;
Valeu amigo. Me ajudou muito. Obrigado
thanks a lot
Your welcome :)
excelent :D thank you
super tutorial
I'm happy to hear that :)
Thanks mate!
Your welcome :)
hi thank you very much for this tutorial,
can you just show us how to dismiss the dialog because i am trying with dialog.dismiss() but it doesn't work
hey did you ever figure it out
I copied the source code but the result of the alert dialog is in full screen. How can i minimize and adjust it to center? Thanks
Hi, please email me (codingdemos@gmail.com) the source code so that i can see what's the problem
thank you bro
Good Video!, I have a question, How can I prevent that the dialog closes when I touch outside it?
Hi, you can call mBuilder.setCancelable(false)
Can you explain How to set custom Layout on Item click Listener of Recyclerview
Hi, please check out the new tutorial about Recyclerview: ruclips.net/video/RIoyRhlo5Oo/видео.html
Great tutorial! Thank you a lot!
My biggest complaint with this video is that it does not show you any useful use case for the button. For example, how do you get the login button to close the dialog on success? (Showing a toast is pretty useless imo), How do I get and set the values of these editTexts? Though it's just a case of accessing their variables it would make this video complete
My dialog layout widgets Id will not shown here. How to solve it?.
Good but you forgot the most important part, how to close it. Don't work with dismiss()
I got it to work define AlertDialog dialog as final. "final AlertDialog dialog = mBuilder.create();" Then you can call dismiss(). Like someone answered here: stackoverflow.com/questions/49349668/how-to-dismiss-custom-alert-dialog
stuck with the (" else ", unexpected token) with a red line, what is the problem!
how can i get the code?
thank you for this helpful video :)
Hi, you can access the source code at this link: github.com/codingdemos/CustomAlertDialogTutorial
Please let me know if you need any help with the code above
*_Thanks for this video_*
Your welcome, happy coding :)
Thanks alot!
Your welcome :)
Thank you
Your welcome :)
can you please make a tutorial on how to enable pop ups by default for web app. because my website need pop ups enable to open after login. i already make app for that website but after login it shows nothing not even pop ups notification.
hey men can you do a tutorial that combine two application in one? btw this is helpful vid goodjob
Hi, thanks for watching :)
Sorry what do you mean by "combine two application in one"?
Like i create app A and the other app B is a source code is it possible to combine those 2 app in one?
Hey I have created two buttons and I did exact same thing as you but my onClickListener is not working at all.
Hi, do you get any error message in the logcat?
@@CodingDemos I fixed it. I had to put onClickListeners after dialog.show(); not before.
Awesome :)
Any text inputed into the Editext shows up as null.
AlertDialog.Builder mBuilder = new AlertDialog.Builder(HomePage.this);
View mView = LayoutInflater.from(HomePage.this).inflate(R.layout.dialog_new_post, null); //does not work when u try to do it the way u have it in your video
EditText etNewPostDialog = (EditText) mView.findViewById(R.id.etNewPostDialog);
Button btnCreatePostDialog = (Button) mView.findViewById(R.id.btnNewPostDialog);
final String newPostDialog = etNewPostDialog.getText().toString().trim();
final String username = SharedPrefManager.getInstance(this).getUsername();
// final String post = etNewPostDialog.getText().toString();
btnCreatePostDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//sendUserPost(username);
Toast.makeText(HomePage.this, newPostDialog, Toast.LENGTH_SHORT).show();
}
});
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
dialog.show();
}
So far every way I have tried it has returned null. Also side question how would you close the dialog. Thanks for the help thus far tho
Hi, do you get any error in the logcat when you try to insert a value in the edittext?
and may i know why this line doesn't work (View mView = getLayoutInflater().inflate(R.layout.dialog_login, null);) do you get any errors?
You can email me (codingdemos@gmail.com) your project code and i'll do my best to help you :)
Appreciate the response, I figured it out, I went about it a bit differently then your video, but still got the correct end result. This is what I did to fix it. Thanks again for the video. Actually helped a lot.
public void displayDialog(){
LayoutInflater layoutInflater = LayoutInflater.from(this);
final View inflator = layoutInflater.inflate(R.layout.dialog_new_post, null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
final EditText etNewDialogPost = (EditText) inflator.findViewById(R.id.etNewPostDialog);
alert.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
final String etNewPostDialog = etNewDialogPost.getText().toString().trim();
//do something
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
alert.show();
}
That's great :)
is this work on AIDE Android App?
I'm sorry i haven't tried that out
thanks
Now I know how i can do that
Awesome, happy coding :)
And what if we want the dialog in a fragment ?
How we can save the text in to the file from edit text by click on yes
You should use something called shared preferences to store the data
i want a dialog box after clicking on icon at action bar i.e add, for this how can we initialize the icon in main activity?
Hi, all you have to do is follow the tutorial that i did which will teach you how to create the option menu, and then you can use this alertdialog code together to show the dialog every time you click on any items in the option menus.
Here is the video tutorial link: ruclips.net/video/EZ-sNN7UWFU/видео.html
Thank You!
How to auto close the popup after button click?
Ajay Sajeev declare the Alert Dialog as a Global Variable and inside the onClickListener type the name of the global Variable and put the cancel button
// Global Variable
AlertDialog ad;
........
onClick{
ad.cancel
}
You surely need to look up at Stack overflow....Even I checked it.
how to disable dialog when click the button...
hi mister plz when i click on button in dialog the email and pasw edit texts are not appeared. how solve it?
Hi, is there any error message in the logcat?
@@CodingDemos i not have error in logcate the app it run but when i clicked button not respons
What font do you use there?
Hi, may I know which part are you referring to?
What? I asked - "What font do you use in Android Studio?"
Oh i'm not using any special font, that is the default font in Android Studio. For the black theme I'm using Dracula :)
how can i open another fragment when is succes ?
great
Happy coding :)