I have a spinner that needs a data source.
That data source has IDs that correspond with a unique ID in a database. I need my spinner to return the ID of the selected item as it appears in the data source.
E.G.:
╔═════════════════════════════════════════════════════╦══════════════════════════════════════════════════════════════╗
║ Data in SimpleArray<ID(An Integer),Name (A String)> ║ Data Spinner Needs<ID (An integer), TextToDisplay(a string)> ║
╠═════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════════╣
║ 234, albert ║ 234, albert ║
║ 1, bob ║ 1, bob ║
║ 3, charly ║ 3, charly ║
╚═════════════════════════════════════════════════════╩══════════════════════════════════════════════════════════════╝
Where the ID in the spinner may be out of order.
When the user selects the entry and presses a button, I want that ID returned by some function, E.G. spinner.getSelectedID();
I have seen this question: How to use SparseArray as a source for Adapter? but I would like to not create an entirely new class for this task. I would like to keep it in a method.
For refrence here is some of my current code that does not work:
public void updateDeleteSelectorItems(){
SparseArray<String> categoryNames = timeDatabase.getColumnData("categories", 1);
ArrayAdapter<SparseArray> spinnerAdapter = new ArrayAdapter<SparseArray>(this, android.R.layout.simple_spinner_dropdown_item, categoryNames)
deleteSelector.setAdapter(spinnerAdapter);
}
Is this possible and how would I go about doing this?
Thanks!