I'm looking a bit of help on how to get a spinner show multiple items but, get the data from a SQLitedatabase.
I'm already able to get data from the database and put it into a spinner with one item. I do this by pulling a column from the database into an ArrayList then adding the ArrayList to the Array Adapter like below, this is my current code:
spinner = (Spinner) view.findViewById(R.id.Spinner);
ArrayAdapter<String> catAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, ArrayListNames);
catAdapter.setDropDownViewResource(R.layout.spinner_item);
spinner.setAdapter(catAdapter);
What I need however is for the spinner to show two items for each row. Right now I'm pulling a column called 'Names' from the database. I want to be able to show the column 'Age' along with that.
So the spinner will look like this:
Item 1: John
33
Item 2: Dave
24
The user can then select either John or Dave from the spinner. I just want to be able to show more than one bit of information in each row. The issue for me, is that it's coming from a database into an ArrayList then into the spinner's adapter.
Does anyone know how I can have that extra row for Age?
I would really appreciate some help, thanks!
EDIT: How I'm getting the data right now.
ArrayList<String> ArrayListNames = new ArrayList<String>();
Cursor c = db.rawQuery("SELECT * FROM table_one", null);
if (c.moveToFirst()) {
do {
ArrayListNames.add(c.getString(c.getColumnIndex("name")));
ArrayListNames.add(c.getString(c.getColumnIndex("age")));
}
while (c.moveToNext());
}
c.close();