When you work with spinners in android, do you have to use a spinner adapter if you set the array in a spinner to a string array declared in strings.xml?
You can use any kind of adapter. For example I use a CursorAdapter to populate from sqlite.
Related
I have an Recyclerview adapter class and searchbox as a header of recyclerview.
Everything is working fine.Now i want to get search suggestion while i type first few letters of items of Recyclerview. Using AutoCompletetextView we needs to pass adapter of Recyclerview:
setAdapter(adapter) but my problem is how should i pass adapter as i am in adapter class.
use after arraylist or dataset values changed
adapter.notifyDataSetChanged();
I'm using the navigation drawer example in Android. What's the easiest way to change the string items in the adapter dynamically? Do I just create a new adapter and set it with my new values?
The problem is I'm altering the string items based on user state logged in and logged out. How do I access it from a non static context and just say update list adapter? It doesn't seem to be re-drawing itself and running my adapter code which is dynamic based on user state, so I guess it runs/inits once and I have to create and load a new adapter if I want to change it later?
Thanks.
You haven't given us much to go on (a little code would be nice), but you can update the data in the ListView by calling notifyDatasetChanged() on the Adapter. If you are not using a custom Adapter e.g. an ArrayAdapter then you can just create a new Adapter instance with different String values and set it to the ListView.
In my Android app, I have an Activity with a Spinner widget. I created it with the following code in onCreate():
this.playerPositionSpinner = (Spinner) this.findViewById(R.id.player_position_text);
ArrayAdapter<CharSequence> positionsAdapter = ArrayAdapter.createFromResource(this, R.array.positions, android.R.layout.simple_spinner_item);
positionsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
this.playerPositionSpinner.setAdapter(positionsAdapter);
Later I want to set the selected item based on a String which I know is a valid item in the Spinner's list? All of the Spinner.setSelection() methods take an int parameter for the position. How do I obtain the position of a String in the Spinners drop-down list?
(You have posted some code now! Yeah! This simplifies my example drastically.)
I recommend using Spinner#setSelection() after calling setAdapter():
playerPositionSpinner.setSelection(positionsAdapter.getPosition("Watermelon"));
Obviously you can replace "Watermelon" with something relevant for your app.
Use your spinner setSelection method:
http://developer.android.com/reference/android/widget/AbsSpinner.html#setSelection(int, boolean)
You need to pass it the integer value of the location of the item. to get the value use your adapter.
You'll need to call playerPositionSpinner.setSelection(position) after creating and setting the Spinner's ArrayAdapter
I have a custom baseadapter that i use to populate a listview. each row that populates contains 4 text views in it. How can I change the text of one of these views without having to repopulate a brand new array into the adapter?
Just change the value into the array and call this method
youradapter.notifydatasetchanged()
I am using a listview with n number of listitems.
I have need to add a spinner with all my listitems.
Is there any option to add the spinner dynamically.
Because i can't determine the number of listitems.
Yes you can, for this you need to create a custom list adapters. See this tutorial for more information
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
Customize row.xml to add Spinner there as per your layout.