How do you make a multiple-choice list from the sqlite database in Android?

I'm new to Android programming, and I wanted to pull list options from a column of the SQLite database for the user to select.

How would I go about doing this?

Like, say the database table to be read is called countries, and the columns were ID, country, and capital.

How would I let the user pick from the list of capitals and have the application return the information in that row?

Asked by: Alfred608 | Posted: 24-01-2022

Answer 1

It sounds like you'd want to present the selections to the user as a Spinner. I would query your database and get a Cursor, wrap that Cursor in a SimpleCursorAdapter, and call setAdapter() on your Spinner instance, passing it the SimpleCursorAdapter instance.

Register to receive onItemSelected events from your Spinner. Then when onItemSelected() is called, you should be able to call getItem(position) on your SimpleCursorAdapter to get the data for the line that was selected. getItem() returns an Object, I'm not entirely sure what you will get back there, but I'm guessing it will actually be a CursorWrapper. I would step into the debugger to verify what that Object actually is that gets returned to you from the getItem() call, and proceed from there.

Answered by: Paul566 | Posted: 25-02-2022

Similar questions

android - Create multiple-choice list by pressing on EditText

Suppose that we have EditText editTextTitle = (EditText) findViewById(; When the user touches the text field the keyboard appears in order to write some text. Instead of this I want to appear a multiple choice list with some elements. When the user confirms the selected items t...

android - Change text color of items in multiple-choice AlertDialog

Can I change text color of each item in a multiple-choice AlertDialog in Android? My AlertDialog popups with below items. Apple Banana Mango Grape When displaying AlertDialog, default text color is black for all items. but I want to do as below. When displaying AlertDialog, text color of Apple should be Red.

android - How to add new items to the persistent multiple-choice AlertDialog?

Basically what I'm trying to do is to imitate the google+ app, where the user can circle other people. The circles are presented in a listview with a checkbox, and the top row of the list is something like "add new circle", and the user can create new circles by clicking on it. I know there are many tutorials on AlertDialog, but I haven't found any tutorials for this task. Can anyone explain how to implement this? Thank yo...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android