开发者

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜