Reputation: 3
This is an easy question but I am not sure the correct jargon to use, so google isn't giving me the result that I want.
I am new to android and have written a few basic application and wanted to make another basic app that has displays information. So it would several main topics and then you can click on one and it will display another list of topics related to the main category and then finally the information.
I am having trouble because I'm unsure whether to just make a bunch of different xml layouts for each category or if I can use an SQL database to store all my data and have the menus point to it. From what I've read SQL seems to be used more when you want to store data vs access it but again i'm new to this. So what would be the best way to approach this.
I just want the layout to be scroll view with a table of 1 column and as many rows I need for the particular topic.
Sorry again I know there is probably a million examples via google but I don't know how to word my question.
Thanks!
Upvotes: 0
Views: 279
Reputation: 5105
If I am reading it correctly, you are looking to create dynamic content from a DB table to fill a view with a list. And the onClick for each list item will open up another list of topics (sub topics / articles in that topic). A click on that sub-topic list item will open up some content.
What you are looking for is the ListView ( http://developer.android.com/resources/tutorials/views/hello-listview.html ). This takes an array of data and a layout that will be rendered with it. It's pretty straightforward.
However, if you are pulling from a DB then a better adapter would be the SimpleCursorAdapter which is designed to show DB rows in a list view (http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html ). I dont think it could be better explained than here Getting stored data from database into ListView..
You can reuse the class that displays the adapter by having the item onClick open the same activity but passing in filter params through the bundle that will use to filter the DB results, depending on what you want.
Upvotes: 1
Reputation: 6342
There are quite a few ways to do this. I would not suggest storing this information in a database if it's simply static data. I would suggest creating a ListView (http://developer.android.com/reference/android/widget/ListView.html) that connects to an ArrayList, with each entry having the topic that you'd like. That way you can add and take off topics as you please. Then, for certain items in the ListView (or all of them if you wish), you can have open either another ListView or a TextView, via an onClick event. I actually just recently answered a question similar to this:
Assign object property to listview
That details how to set up an ArrayList, ListView and ArrayAdapter that iterates through the ArrayList and acts as a sort of "bridge" between the contents of your ArrayList and the ListView (it's a Cursor implementation). Let me know if you need any more information.
Upvotes: 0