Reputation: 2231
At the moment, I have a category Spinner. When user click to the spinner, a drop down list with different categories such as food, services, education, etc. will be displayed.
I get the categories from the database via a cursor and I am able to display what I get from the database to the spinner.
My question is: How can I add one more options to the spinner, after binding all categories to it? What I want to do is to add "All" option to the top of the drop down list when user clicks to the spinner.
final DBAdapter mDB = new DBAdapter(getActivity());
mDB.openDB();
List<String> categoryFilter = mDB.getItemByFilteredCategory();
ArrayAdapter<String> filterAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, categoryFilter);
spnFilter.setAdapter(filterAdapter);
Thanks in advance.
Upvotes: 2
Views: 903
Reputation: 4613
Could the insert method of the arrayadapter be of any help?
ArrayAdapter.html#insert(T, int)
filterAdapter.insert("First String", 0); //adds myObject to the first position.
Upvotes: 3
Reputation: 10079
To add a value to the spinner use setAdapter method and ArrayAdapter Class.
Eg: ArrayAdapter.add(value);
Add all the values in string.
For Eg: Refer these android docs.
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item></string-array>
</resources>
If you add values in String,Then set the name in a order which you want in top.
Upvotes: 0