Thank you so much, you save my day, i've been frustrated to build an spinner outside the oncreate method, then i realized from your video it need some view inflater, thank you so much
Hi, you can add another button and follow the steps that i showed in the video. I want to ask you is the second spinner that you want to add related to the first spinner? If they are, then i will suggest you to add 2 spinner in one dialog instead of having 2 dialogs with 2 spinners. For example: You have 1 spinner that contain list of restaurant inside a dialog and another spinner that contain list of dishes inside another dialog..that will make it kind of complicated for the user to make a choice, instead you can just add those 2 spinner under one dialog which will make it very easy for the user and less troublesome. Happy coding :)
Like coding demos said, but be aware if you want to add more than one of those kinda items(Spinners, Edittexts and textviews, etc etc), you might end up having to create your own layout, then add in those items to that kayout, and then add the layout to the dialog eg: LiniarLayout layout = new LiniarLayout(v.getContext()); //create your spinners (using spinner_1 and spinner_2 as example) layout.setView(spinner_1); layout.setView(spinner_2); //Assuming you called your dialog dialog_1 dialog_1.setView(layout); Else only one spinner will be shown
Thanks for the tutorial! I've learned a lot... Is there any way to change the color of the spinner text? For example: Macdonald --> red color and Burger King in green color.
Hi, You can do it like this: mBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if(!mSpinner.getSelectedItem().toString().equalsIgnoreCase("Choose a restaurant…")) { startActivity(new Intent(MainActivity.this, SecondActivity.class)); dialogInterface.dismiss(); } } }); Happy coding :)
suppose if I have multiple spinners with different values, based upon selected values I have to open the new activity So how can I do that?? Can anyone Help me!?
hi sir i'm a new creator in android studio, but i have some problem there.. that's very hard to me because i need to change or switch the activity after choose and click yes/ok, can you help me sir ? so it is not just make some toast, but for switch the activity too.. thanks sir
Hi, so let's say we want to show the chosen value in a textview inside the dialog..here are the steps: - Open dialog_spinner.xml file and create a simple textview like this: - Open MainActivity.java file and define the textview inside onClick method like this: TextView mValue = (TextView)mView.findViewById(R.id.textview); - Inside mBuilder.setPositiveButton onClick method you set the chosen value inside the new textview that we've just created like this: mValue.setText(mSpinner.getSelectedItem().toString()); - Don't forget to remove dialogInterface.dismiss() from mBuilder.setPositiveButton onClick method to be able to see the chosen value, otherwise the dialog will be dismissed and you won't be able to see the chosen value That's it..i hope that answer your question, please do let me know if you need more help. Thanks and happy coding :)
Hi, I'm sorry I didn't put the source code on Github back then. You can let me know if you are having any issues with code and I'll try my best to help you out :)
Dude thank you. Spinners have got to be the most convoluted impossible to understand thing out there.
You're welcome 😀
Thank you so much, you save my day, i've been frustrated to build an spinner outside the oncreate method, then i realized from your video it need some view inflater, thank you so much
very helpful thankyou!
what do i do if i want to make more than one button that has a spinner?
like two buttons both with spinners?
Hi, you can add another button and follow the steps that i showed in the video.
I want to ask you is the second spinner that you want to add related to the first spinner? If they are, then i will suggest you to add 2 spinner in one dialog instead of having 2 dialogs with 2 spinners.
For example: You have 1 spinner that contain list of restaurant inside a dialog and another spinner that contain list of dishes inside another dialog..that will make it kind of complicated for the user to make a choice, instead you can just add those 2 spinner under one dialog which will make it very easy for the user and less troublesome.
Happy coding :)
Like coding demos said, but be aware if you want to add more than one of those kinda items(Spinners, Edittexts and textviews, etc etc), you might end up having to create your own layout, then add in those items to that kayout, and then add the layout to the dialog
eg:
LiniarLayout layout = new LiniarLayout(v.getContext());
//create your spinners (using spinner_1 and spinner_2 as example)
layout.setView(spinner_1);
layout.setView(spinner_2);
//Assuming you called your dialog dialog_1
dialog_1.setView(layout);
Else only one spinner will be shown
Thank you so much) Best video about dialog spinner!
I'm gladly thankfull that i found out your video, it helps me a lot. I appreciate your work, THANKS!!!
Thanks for the tutorial! I've learned a lot...
Is there any way to change the color of the spinner text?
For example: Macdonald --> red color and Burger King in green color.
Thank you so much!!!! You saved my life. My research project is alive thanks to you. Awesome and useful tutorial!
You're welcome. I'm happy to help 😀
Thank you very much, you just saved my thesis!!
You're welcome 😀
Thank you very much...really helpful tutorial..keep it up!!
Sir how can I add those items from spinner to my database then view it in a different fragment?
Thanks
your tutorial its so useful
Thank you so much!
nice.. easy to understand
I'm happy to hear that :)
you just solved my life, thanks bro
Thanks Great Effort
You're welcome 😃
Thank you .Awesome explanation and very helpful for me.
Thanks! Very clear and simple
can you show how can go to new page when i click the item on the spinner?
Hi, You can do it like this:
mBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if(!mSpinner.getSelectedItem().toString().equalsIgnoreCase("Choose a restaurant…")) {
startActivity(new Intent(MainActivity.this, SecondActivity.class));
dialogInterface.dismiss();
}
}
});
Happy coding :)
Why i get some error in line mSpinner.setAdapter(adapter); ??
Nice tutorial.
Thank you!
Your welcome :)
If I wanted to add dynamically other components to this custom dialog/layout, how could I do that?
Hope you can help me!
You saved my life thanks
Your welcome, I'm happy to help :)
Thank You sooooo much
Really helpful to me. thanks.
Your welcome :)
Great one,thank You.
What abbout if I want to do this with Kotlin
suppose if I have multiple spinners with different values, based upon selected values I have to open the new activity So how can I do that??
Can anyone Help me!?
hi sir i'm a new creator in android studio, but i have some problem there.. that's very hard to me because i need to change or switch the activity after choose and click yes/ok, can you help me sir ?
so it is not just make some toast, but for switch the activity too.. thanks sir
Hi, just add the following code inside the button OnClick method:
startActivity(new Intent(MainActivity.this, NewActivity.class));
how to show spinner value using SQLite database
Nice dude! keep up the good work
Thanks for watching :)
awesome
gracias
Key statement never forget :
- setDrop
- if (mspinner.getSelectedItem.toString().equalsIgnoreCase() { ....}
- mBuilder.setView(mView)
- mBuilder.create()
i am having error in "mspinner" and "DialogInterface" ,i am using android studio version 3.0.1.
Hi, what is the error that you see?
Very Nice.
How to validate a spinner
Hi, you can email (codingdemos@gmail.com) me your code.
good video
Happy coding :D
thanks
How do you display the chosen value into a textview instead of a toast?
Hi, so let's say we want to show the chosen value in a textview inside the dialog..here are the steps:
- Open dialog_spinner.xml file and create a simple textview like this:
- Open MainActivity.java file and define the textview inside onClick method like this:
TextView mValue = (TextView)mView.findViewById(R.id.textview);
- Inside mBuilder.setPositiveButton onClick method you set the chosen value inside the new textview that we've just created like this:
mValue.setText(mSpinner.getSelectedItem().toString());
- Don't forget to remove dialogInterface.dismiss() from mBuilder.setPositiveButton onClick method to be able to see the chosen value, otherwise the dialog will be dismissed and you won't be able to see the chosen value
That's it..i hope that answer your question, please do let me know if you need more help.
Thanks and happy coding :)
Thank you!
Your welcome :)
where is the source code ????
Hi, I'm sorry I didn't put the source code on Github back then. You can let me know if you are having any issues with code and I'll try my best to help you out :)
falto el setVIew(mView);
How to position text so it does not go over the background.
i.stack.imgur.com/YlGPO.png
You can add this line to position it below the background:
android:layout_below="@+id/background"