views:

82

answers:

1

Hello everyone,

My program will show data based on selection from two spinners (month and year). Based on month and year, it will query DB and displays the content in listview.

I created two spinners and populate with array string. Then I created two spinner views, two arrayadapters and set onItemSelected listeners and set adapter to the views. Then I use cursor to get query from DB, then put the result into simple cursor adapter and put them into list adapter. Finally I use list view to add this listadapter. Result shows properly. It is OK when the queries is not too much. But when there are lots of queries, it is difficult to see. So I want to implement paging for my program. For example: I get 100 queries, and I want to show them like 10 or 20 queries per page. I can control how many records per page via another spinner.

But the main problem is that I don't know how to get subset data or subview from return queries (listview).

Are there any methods in listadapter or android can do that ? I'm still new in android. I also read some documents about getView(), I don't understand and not sure whether it can help on my purpose.

Thanks for advise or suggestion !!

Tom

A: 

I have encountered this issue too. Two possible approaches you may try:

  • Definitely you need to extend ArrayAdapter. Overriding getView() is the key (as you suggested). Depending on the actual position you may inflate another list to each position. So, it is possible to have several lists in a list. The only catch is that when you move, you move both lists simultaneously.

  • Another approach is to create something that looks like a list but is not a list in fact. Create layout in a way that you take ScrollView, put LinearLayout into that, and then programatically create several LinearLayout childs. Each child should contain list of fixed size (e.g. 10), search queries (represented by TextView elements), also created programatically. So basic layout contains just ScrollView and ListView and the rest you add from code.

You may check answer on issue below, since it offers something simple but similar to what you need:

expandable list example

Desiderio