Thank you for the tutorial! But would you also please tell how to make them work? So for instance, if I choose "Work" - first thing happens "home" - second and so on.
hello there...very helpful tutorial..just need little more help...i want to show this Spinner in a Custom Dialog..please tell me where should i initialise the Spinner..??
sir, Thank you for the wonderful explanation. I am doing it on java itself instead of xml, just because it found it easier. Now, I have another spinner immediately after this . If the user selects "home' in this spinner i want to show "Clean, cook, wash or sleep" in the second spinner and if the user selects "office" I want to show "meeting, project, resources" only and not the things that are to be done at home. Please help me. I have 38 different items in the first spinner and the second will have 576 items divided into these 38 items.
If anyone is facing this problem that the spinner is showing the list items but the setOnItemSelectedListener() is not getting executed, then try doing all that work right where you created the list. I spent the last 27 hours of my life trying to solve it. Finally is working for me.
Excellent tutorial. Thanks. I was successful at the first trial, thanks to your lucid explanation. Now suppose the user has chosen an item in the spinner. I want to use his input for further work. How do I do it? Do you have a tutorial for that?
Hi, great i'm happy to hear that :) You can get the selected value from the spinner like this: String spinnerValue = spinner.getSelectedItem().toString();
Conversion. For example: Two edittext and two spinners. On the first edittext you write down the value (42), and you select the spinner by the kilometer. And on the second spinner you choose the meter, and immediately on the second edittext shows the answer: (42000) and immediately saved the data in the database. How to do this?
I implemented the code but shows error ((Inconvertible types; cannot cast 'android.view.View' to 'com.example.myproject.Spinner')) how to fix it please????
Because by default now when you create a new project in Android studio, the layout XML file will have Constraints layout as the root layout. You can change it to other layout if you want to.
Hi Coding Demo,I would like to know if this is the best way(Clean and simple) to center text on a spinner. stackoverflow.com/questions/24317634/how-do-i-center-text-in-a-spinner-in-android Thank you in advanced!
Great video, but why did you not initially set the "android.R.layout.simple_list_item_1" instead of initially using "simple_spinner_dropdown_item" ?? Thank you! This video and I am sure the following will help me greatly.
Its a nice video! I would have liked if there are somethiing more after.. like any reaction of the choice we made. "if (Text.equals....)" something like this :)
Ok, thanks. Now, I want to use the chosen value to open a particular pdf file, which is available in resources. I have written:- // attempting to use spinner value selectedPlan=mySpinner.getSelectedItem().toString(); // extracted value selectedPlan may be used to display appropriate plan if (selectedPlan=="Open Spaces"); Intent i=new Intent(ArchPlans.this,OSPlan.class); startActivity(i); why doesn't this work?
Hi, you need to use spinner.setOnItemSelectedListener, this will allow you to select an item from the spinner. So if you want to select home you do it like this: mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int i, long l) { switch (i) { case 0: Toast.makeText(MainActivity.this, "Selected home", Toast.LENGTH_SHORT).show(); break; } } @Override public void onNothingSelected(AdapterView adapterView) { } }); I hope that helps :)
I followed exactly the code, But my spinner looks white blank. no arrow, no line bellow the items. I tried also other R.layouts but none worked. why is that?
Hi, here is how you can do it: 1- Add another value to the Spinner string-array and name it "Please select a value". The string-array will look like this: Please select a value Home Work Other Custom 2- Let's say later when a user taps on a button, inside onClick method you check the spinner value. If the spinner value is equal to "Please select a value", you will show a Toast message informing the user like this: if(mySpinner.getSelectedItem().toString().equalsIgnoreCase("Please select a value")){Toast.makeText(MainActivity.this, "Please select a value", Toast.LENGTH_SHORT).show(); }
When I try to reach the data used to populate the spinner on the third context @5:25 after I type getResources().getStringArray(R.array.myarray)); the array right after the array R. is highlighted red. I don't seem to have the class array. How can I fix that?
Hi, thank you for your prompt reply! Your tutorials are awesome. I fixed the issue, turns out I just had to invalidate the cache/restart, and that did it for me.
Thank you for awesome tutorial. :) i want to know that how can we add image or icon before the text in spinner. Like in spinner it should show the country names with its flags. it would be great if you can help me out. thanks!
Thanks for watching :) Here is a tutorial that will help you with creating custom spinner to be able to show country names with it's flags: abhiandroid.com/ui/custom-spinner-examples.html
great video !!! excellent!!!! bt here i am stuck with a problem in my app ,i want to use two spinners first spinner selects departure place second spinner selects destination place I want to get source and destination and compare those with the predifined place eg spinner1 newyork spinner2 paris nw i want to use if (spiner1value is equal to newyork and spiner2 value is equal to paris) open an activity it works fine qith one spinner but when using two spinners i dont know how to use this, please make a tutorial on how to use two spiner and when u press a button it should start a new activity if the places match when im using only one spinner in app then
Hi, you can define a spinner for departure and destination like you did there, then inside a button onClickListener you can check for the value before starting a new activity for example: if(spinnerDepart.getSelectedItem.toString.equalIgnoreCase(value) && spinnerDestin.getSelectedItem.toString.equalIgnoreCase(value)){ Intent mIntent = new Intent(MainActivity.this, DetailActivity.class) startActivity(mIntent); }else{ //You can show a toast message informing the user that there was something wrong } Please do let me know if you need more help, happy coding :)
Coding Demos thanku for the help i just found the solution in net which is same as you told now ,i found it after 8hours u r equaly genious thanku package com.mycompany.myapp; import android.app.*; import android.os.*; import android.widget.*; import android.widget.Spinner.*; import android.widget.SpinnerAdapter.*; import android.view.*; import android.content.*; public class MainActivity extends Activity { Spinner mSpinner1,mSpinner2; String category[]={"kalpane","B.C.Road","Mallur","Mangalore"};
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mSpinner1=(Spinner)findViewById(R.id.spinner1); mSpinner2=(Spinner)findViewById(R.id.spinner2); ArrayAdapter adapter1= new ArrayAdapter(this,R.layout.test,category); ArrayAdapter adapter2= new ArrayAdapter(this,R.layout.test,category); mSpinner1.setAdapter(adapter1); mSpinner2.setAdapter(adapter2);
} public void onButtonClick(View l) { if(l.getId() ==R.id.button) { //First get the selected country name String sp1Val = mSpinner1.getSelectedItem().toString(); String sp2Val = mSpinner2.getSelectedItem().toString(); // Then compare both spinner values: if(sp1Val.equalsIgnoreCase("mallur") && sp2Val.equalsIgnoreCase("kalpane")){ Intent i = new Intent(MainActivity.this,mallur.class); startActivity(i); } } } }
Coding Demos thanku soo much i have another problem i couldnt find exact solution in web i am absolutly new to android designing when i design ,i design in AIDE app for android i design for a 5.5 inch phone so i use fixed dp size for some of layouts and button so as to fit in perfectly for my phone but when i install in diffrent phones the fixed dp creates a problem the layout gets croped in smaller phones please make a video on how to make complex layouts that will fit in for all mobile phones bt at the same time i want to adjust the buttons position at some place that i cannot use wrapcontent and matchparent it would be a great help
Hi, thank you :) Now about your question: You can just show a simple Toast message when the user for example selected an invalid item from your spinner
Hi, first you get the user selected value from spinner like this: String selectedValue = spinner.getSelectedItem().toString(); To write data in SQLite db you will use ContentValues like this: SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("spinner value", selectedValue); database.insert("table_name", null, values); database.close(); I hope that helps :)
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!?
Whether or not this question still needs answered, to do so you would need to select the data from the strings array, and depending on which data is selected, a switch be used to push the user to a different activity via an intent.
Hi. Thank you for the video about the spinner. I am learning android programming. I am Sudanese but I live and work in KSA. I teach English in a private institute. I write programs that convert the English exercise in the textbook into interactive mobile apps to be installed on my students mobile phones. Sometimes I get stuck. That’s why I need a mentor. If you can help, let me know so that we can agree on a price and a method of payment. If you are not interested, please recommend someone who can help me when I get stuck.
Hi, your welcome :) Yeah i'm interested, please email me (codingdemos@gmail.com) the details about the app and any challenges that you face during development. Thanks.
@@CodingDemos This is my Java file code: Spinner langSpinner = (Spinner) findViewById(R.id.langSpin); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.languagesSett, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); langSpinner.setAdapter(adapter); This is from the Android Developers website code by the way. (Sorry if I'm not showing you what you actually wanted, I am just thinking that I have to show you the code.)
Your turorial is so good. Only issue is, the dark background you have used. You could have changed the dark background color of the IDE to a brighter one, at least for the turorial sake. Thank you.
Thank you, very hard to find tutorials with someone that speaks clearly.
Your welcome, I'm happy to help :)
Thank you for the tutorial!
But would you also please tell how to make them work?
So for instance, if I choose "Work" - first thing happens
"home" - second and so on.
sounds like an "if","then" function
on click listnr
Thank you! But how do you print it with toast message or get the selected info?
This looks good but how can you connect this with your database items?
hello there...very helpful tutorial..just need little more help...i want to show this Spinner in a Custom Dialog..please tell me where should i initialise the Spinner..??
Hi, i'm currently working on a tutorial that will show you how to do that. I'll let you know when it's live
Thanks for watching :)
Hi, the tutorial is now live on the channel, here is the link: th-cam.com/video/nlqtyfshUkc/w-d-xo.html
Enjoy :)
sir, Thank you for the wonderful explanation.
I am doing it on java itself instead of xml, just because it found it easier.
Now, I have another spinner immediately after this . If the user selects "home' in this spinner i want to show "Clean, cook, wash or sleep" in the second spinner and if the user selects "office" I want to show "meeting, project, resources" only and not the things that are to be done at home. Please help me.
I have 38 different items in the first spinner and the second will have 576 items divided into these 38 items.
use ifs...
If anyone is facing this problem that the spinner is showing the list items but the setOnItemSelectedListener() is not getting executed, then try doing all that work right where you created the list. I spent the last 27 hours of my life trying to solve it. Finally is working for me.
Can you show if item clicked goes to that activity
Nice video tutorial sir, but i have a question how to add border line like in Plain Text?
Excellent tutorial. Thanks. I was successful at the first trial, thanks to your lucid explanation.
Now suppose the user has chosen an item in the spinner. I want to use his input for further work. How do I do it? Do you have a tutorial for that?
Hi, great i'm happy to hear that :)
You can get the selected value from the spinner like this:
String spinnerValue = spinner.getSelectedItem().toString();
I'll just start sending hate mail and or begging the phone makers. Thanks for offering to teach me.
Why there is no simple_list_item for me, I wonder when did you created this
Conversion. For example: Two edittext and two spinners. On the first edittext you write down the value (42), and you select the spinner by the kilometer. And on the second spinner you choose the meter, and immediately on the second edittext shows the answer: (42000) and immediately saved the data in the database. How to do this?
Is it written in kotlin or java?
This one is written in Java
hye sir , thanks for the tutorial .
but i have a question,
how to send the selected spinner item into PHPMySQL ? thanks.
Did you find it?
hello... so how can I access the data which has been selected in the spinner...
I implemented the code but shows error ((Inconvertible types; cannot cast 'android.view.View' to 'com.example.myproject.Spinner')) how to fix it please????
Very concise, good explanation, friendly. Thank you.
in your activity_main why does it show RelativeLayout for you but constrained layout for me?
Because by default now when you create a new project in Android studio, the layout XML file will have Constraints layout as the root layout. You can change it to other layout if you want to.
Tq for this video.. Can i have video that how can i add item to Spinner dynamically?
Do you know how to make it store in sqlite database?
Excellent Tutorial, Simple and clean commands!! Thank you very much.
Your welcome, happy coding :)
Hi Coding Demo,I would like to know if this is the best way(Clean and simple) to center text on a spinner.
stackoverflow.com/questions/24317634/how-do-i-center-text-in-a-spinner-in-android
Thank you in advanced!
Hi, yeah the accepted answer looks simple but i can't say it's the best way to do it :)
Great video, but why did you not initially set the "android.R.layout.simple_list_item_1" instead of initially using "simple_spinner_dropdown_item" ?? Thank you! This video and I am sure the following will help me greatly.
Its a nice video! I would have liked if there are somethiing more after.. like any reaction of the choice we made. "if (Text.equals....)" something like this :)
Ok, thanks. Now, I want to use the chosen value to open a particular pdf file, which is available in resources. I have written:-
// attempting to use spinner value
selectedPlan=mySpinner.getSelectedItem().toString();
// extracted value selectedPlan may be used to display appropriate plan
if (selectedPlan=="Open Spaces");
Intent i=new Intent(ArchPlans.this,OSPlan.class);
startActivity(i);
why doesn't this work?
dont put ; after if and write both lines in if's curly braces
Great Video!
My ques is how to use the same if I want suggestions of my contacts?
how can i show data from the spinner ? for example if i select home so i need to display that selected option . kindly help me ASAP
Hi, you need to use spinner.setOnItemSelectedListener, this will allow you to select an item from the spinner. So if you want to select home you do it like this:
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView adapterView, View view, int i, long l) {
switch (i) {
case 0:
Toast.makeText(MainActivity.this, "Selected home", Toast.LENGTH_SHORT).show();
break;
}
}
@Override
public void onNothingSelected(AdapterView adapterView) {
}
});
I hope that helps :)
That's correct, thanks for sharing :)
how to change the background color of drop down sub-manu
Excellent Tutorial!!
No matter what or how I do it I keep getting unsupported type string-array error... how can I fix that?
Hi, can you please show me the string array that you want to create?
This is an excellent tutorial. Very useful. Thank you so much.
each time i reopen my spinner application
i get the option i selected previously. how to reset it?
n change the color of the text selected
Simple and perfect. Thanks!
I followed exactly the code, But my spinner looks white blank. no arrow, no line bellow the items. I tried also other R.layouts but none worked. why is that?
Hmm that is strange. Can you please email me (codingdemos@gmail.com) your project source code? I need to see what is causing this issue
How could I add a label to the spinner which is not selectable?
which is appear innitially when no item is selected.
thanks in advance.
Hi, here is how you can do it:
1- Add another value to the Spinner string-array and name it "Please select a value". The string-array will look like this:
Please select a value
Home
Work
Other
Custom
2- Let's say later when a user taps on a button, inside onClick method you check the spinner value. If the spinner value is equal to "Please select a value", you will show a Toast message informing the user like this:
if(mySpinner.getSelectedItem().toString().equalsIgnoreCase("Please select a value")){Toast.makeText(MainActivity.this, "Please select a value", Toast.LENGTH_SHORT).show();
}
In the spinner, how to make an optional spinner stored the data in a database
Beautifully explained..!
Thank you :)
Nice tutorial. Not quite complete without mentioning how to obtain the selected value though...
Hi, you can obtain the value from the spinner like this: String spinnerValue = spinner.getSelectedItem().toString();
Will spinner be able to scroll when the options are too many to many to be shown in one view
Hi, yes it will scroll
Could you upload a video showing how to validate spinner in form filling
Thank you so much nice tutorial
When I try to reach the data used to populate the spinner on the third context @5:25 after I type getResources().getStringArray(R.array.myarray)); the array right after the array R. is highlighted red. I don't seem to have the class array. How can I fix that?
Hi, did you create the string-array items inside strings.xml file?
Hi, thank you for your prompt reply! Your tutorials are awesome. I fixed the issue, turns out I just had to invalidate the cache/restart, and that did it for me.
Awesome, i'm glad you got it fixed and thanks for sharing the solution :)
Thank you for awesome tutorial. :) i want to know that how can we add image or icon before the text in spinner. Like in spinner it should show the country names with its flags. it would be great if you can help me out. thanks!
Thanks for watching :)
Here is a tutorial that will help you with creating custom spinner to be able to show country names with it's flags: abhiandroid.com/ui/custom-spinner-examples.html
Great tutorial.
Thanks for watching :)
What if the data is coming from the server and needs to be set up as dynamic. ?
Hi, you can initialize an array that will hold the data coming from the server, then you will use this array inside the spinner to show the result
great video !!! excellent!!!! bt here i am stuck with a problem
in my app ,i want to use two spinners
first spinner selects departure place
second spinner selects destination place
I want to get source and destination
and compare those with the predifined place
eg spinner1 newyork
spinner2 paris
nw i want to use
if (spiner1value is equal to newyork and spiner2 value is equal to paris)
open an activity
it works fine qith one spinner
but when using two spinners
i dont know how to use this,
please make a tutorial on how to use two spiner and when u press a button
it should start a new activity
if the places match
when im using only one spinner in app
then
Hi, you can define a spinner for departure and destination like you did there, then inside a button onClickListener you can check for the value before starting a new activity for example:
if(spinnerDepart.getSelectedItem.toString.equalIgnoreCase(value) && spinnerDestin.getSelectedItem.toString.equalIgnoreCase(value)){
Intent mIntent = new Intent(MainActivity.this, DetailActivity.class)
startActivity(mIntent);
}else{
//You can show a toast message informing the user that there was something wrong
}
Please do let me know if you need more help, happy coding :)
Coding Demos thanku for the help
i just found the solution in net which is same as you told now ,i found it after 8hours
u r equaly genious thanku
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.widget.Spinner.*;
import android.widget.SpinnerAdapter.*;
import android.view.*;
import android.content.*;
public class MainActivity extends Activity
{
Spinner mSpinner1,mSpinner2;
String category[]={"kalpane","B.C.Road","Mallur","Mangalore"};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSpinner1=(Spinner)findViewById(R.id.spinner1);
mSpinner2=(Spinner)findViewById(R.id.spinner2);
ArrayAdapter adapter1= new ArrayAdapter(this,R.layout.test,category);
ArrayAdapter adapter2= new ArrayAdapter(this,R.layout.test,category);
mSpinner1.setAdapter(adapter1);
mSpinner2.setAdapter(adapter2);
}
public void onButtonClick(View l)
{
if(l.getId() ==R.id.button)
{
//First get the selected country name
String sp1Val = mSpinner1.getSelectedItem().toString();
String sp2Val = mSpinner2.getSelectedItem().toString();
// Then compare both spinner values:
if(sp1Val.equalsIgnoreCase("mallur") && sp2Val.equalsIgnoreCase("kalpane")){
Intent i = new Intent(MainActivity.this,mallur.class);
startActivity(i);
}
}
}
}
That's great...Good luck with your app and let me know if you need any help :)
Coding Demos thanku soo much
i have another problem i couldnt find exact solution in web
i am absolutly new to android designing
when i design ,i design in AIDE app for android
i design for a 5.5 inch phone
so i use fixed dp size for some of layouts and button so as to fit in perfectly for my phone
but when i install in diffrent phones
the fixed dp creates a problem
the layout gets croped in smaller phones
please make a video on how to make
complex layouts that will fit in for all mobile phones bt at the same time
i want to adjust the buttons position at some place that i cannot use wrapcontent and matchparent
it would be a great help
Thank you for sharing. This is an excellent tutorial.
Can you tell me how to do.."from and to date" validation
Very helpful, thank you for that!
Hi its Good Tutorials but how to do separator for every item like line .
use View and make layout height as 1 dp or as per ur requirement
Coding Demos Thank you very much for this awesome tutorial, Demo
Your welcome :)
nice video sir
by the way, i want to make a spinner, and set error on it, can you teach me how to do it?
Hi, thank you :)
Now about your question: You can just show a simple Toast message when the user for example selected an invalid item from your spinner
how to save this spinner option into firebase database?
when a user select a data from the spinner, how can i insert his choose in sqlite database?
Hi, first you get the user selected value from spinner like this:
String selectedValue = spinner.getSelectedItem().toString();
To write data in SQLite db you will use ContentValues like this:
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("spinner value", selectedValue);
database.insert("table_name", null, values);
database.close();
I hope that helps :)
@@CodingDemos i will try, thank you so much ❤️
Anyone knows where to put the code if you have individual tabs java classes?
how i can do this in navigation menu?
thanks for the help !
Many Many Thanx
does anybody know how to add a spinner on a google map activity? i cant seem to put it on the google map.xml
Wonderful!
Thank you very much!
You're welcome :)
Thanks!
Anyone help me on why I have no myAdapter option?
ArrayAdapter myAdapter = new ArrayAdapter(getContext(),R.layout. is beter
Great you should have more Subscribers!
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!?
Whether or not this question still needs answered, to do so you would need to select the data from the strings array, and depending on which data is selected, a switch be used to push the user to a different activity via an intent.
AWSM..THANKYOU
Your welcome :)
Thank You.
Your welcome :)
Hi. Thank you for the video about the spinner.
I am learning android programming. I am Sudanese but I live and work in KSA. I teach English in a private institute. I write programs that convert the English exercise in the textbook into interactive mobile apps to be installed on my students mobile phones. Sometimes I get stuck. That’s why I need a mentor. If you can help, let me know so that we can agree on a price and a method of payment. If you are not interested, please recommend someone who can help me when I get stuck.
Hi, your welcome :)
Yeah i'm interested, please email me (codingdemos@gmail.com) the details about the app and any challenges that you face during development.
Thanks.
Thank you!!!!!
Thank you
Please help me, I get an error when I build that says: error: cannot find symbol variable array.
I did everything correctly, please help.
Hi, did you create the array items inside strings.xml file?
@@CodingDemos Yes I did (Thanks for the reply):
English
Espanol
Your welcome :)
Can you please show me how you reference that string-array inside the java file?
@@CodingDemos This is my Java file code:
Spinner langSpinner = (Spinner) findViewById(R.id.langSpin);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
R.array.languagesSett, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
langSpinner.setAdapter(adapter);
This is from the Android Developers website code by the way.
(Sorry if I'm not showing you what you actually wanted, I am just thinking that I have to show you the code.)
The code you shared with me works fine. Try to clean and rebuild your project
The video is not complete....
need event listeners in spinner
Hi, here is part 2 of the tutorial where you learn about the spinner event listener: th-cam.com/video/mrcrFY-5c-c/w-d-xo.html
Your turorial is so good. Only issue is, the dark background you have used. You could have changed the dark background color of the IDE to a brighter one, at least for the turorial sake.
Thank you.
When I run this on my phone it crashes anyone have any idea why?
Can you please tell me what is the error that you see in the logcat?
Hi I'm to implement the pdf viewer into a fragment, my error is, E/Qmage: isQIO : stream is not a QIO file
Hi, i guess the crash is related to the pdf viewer that you are trying to use inside the fragment
Any solutions?
I need to see some code to be able to help you, you can email me (codingdemos@gmail.com) and i'll see what i can do
Its not working in new version 2021
plz anyone correct this..
if i found I will add it in comment.
Guys who facing same problem check my reply.
Hi, may I know which part is not working? Is there any error message?
6:09 myAdapter is coming in red
What is the error that you see when you hover your mouse over that line?
5:48
where the fuck do u get MyAdapter from?
in final, mySpinner.toString()
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"
I add this line in activity_main.xml layout and there is still text over the background of the spinner
Can you please send me (codingdemos@gmail.com) the code for the activity_main.xml?
doesn't do anything. useless
thank you for the video!