How can I create an empty spinner with no elements in it and add them later?
ArrayAdapter<String> aSpin = ArrayAdapter.createFromResource(this, null , null);
Doesnt work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m curious, in which scenario would you want an empty spinner?
anyway, a spinner with a null object will give you an annoying exception. If you really want a spinner “empty”, i would recommend you to create a normal spinner with a fake object. That object would be a string like ” “. So, it won’t be empty but it will look like if it is.
— Edit —
In order to use a spinner with objects, you will need an adapter. So, first, if you want an empty spinner, just find its view from your layout and that’s all. You will have an empty spinner:
Then, when you need to add your items to the spinner, create an array with those items, then add them to the adapter, and add the adapter to your spinner. For example, let’s say that you will have strings: