I'm trying to list each record in a sqlite database as a button in my android app. I'm planning on creating a cursor and calling up each record in a while loop. this is logically where I would place the code to generate a button that serves an intent(etc.. irrelevant) for each of the records. Once i started this I realized that I've only learned how to create views by directly coding them into my .xml files. as the information is being called from a database, it would be impractical to have the buttons made in advance. they need to be created when the application is opened. any pointer in the right direction would be much appreciated. (I p开发者_开发百科romise to pay it forward).
How are you laying out the buttons ? You can display the buttons in a custom list view. Create a xml that has the layout of each row ( in your case just a button ) and then at runtime you can set the text ,listeners and any other properties for each button.
-Salil
Building on Salil's answer, you might want to use a ListView backed by a SimpleCursorAdapter.
See this example of SimpleCursorAdapter in ListViews
Let me know if you need more details - I don't have my source code handy at the moment.
Hope this helps,
Phil Lello
精彩评论