Hi,
I want to save the selected item somehow, so that the selected item is
shown as the selected spinner item next time the same activity is
launched. How can I achieve that?
Thanks,
public class MyActivity extends Activity {
private Spinner mSpinner;
...
public void onCreate(Bundle savedInstanceState) {
Cursor cursor = mDbHelper.fetchAllItems(); // get all items
from database.
startManagingCursor(cursor);
List<String> items = new ArrayList<String>();
while (cursor.moveToNext()) {
items.add(name);
};
Collections.sort(items);
ArrayAdapter<CharSequence> adapter = new ArrayAdapter(
this, android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(
new OnItemSelectedListener() {
public void onItemSelected(
AdapterView<?> parent, View view, int
position, long id) {
// QUEASTION: I WANT TO SAVE THE SELECTION
SOMEHOW,
// SO THAT next the selected item is selected/
shown in the spinner by default
}
});
}
----
A related question: is there a way that I can use SimpleCursorAdapter
directly and sort the displayed items in alphabetic order? -- the
default SimpleCursorAdapter does not seems to be able to do that.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---