1

I want to make a timetable app for the buses of my city. But, my code is too long. I have a MyAdapter class but as each bus line needs a different adapter my code started to seem like this:

MyAdapter list1 = new MyAdapter<String>(this,
        android.R.layout.simple_list_item_1, R.id.timelist, List1);
MyAdapter list2 = new MyAdapter<String>(this,
        android.R.layout.simple_list_item_1, R.id.timelist, List2);
MyAdapter list3 = new MyAdapter<String>(this,
        android.R.layout.simple_list_item_1, R.id.timelist, List3);
// ...

And for each of this I have:

setAdapter(listx);

in regular places. Is there any easier way to write MyAdapter object which will need less copy-paste things? (I cannot call that a code.)

Onur
  • 134
  • 2
  • 16
  • 1
    You might want to use [`ExpandableListView`](http://developer.android.com/reference/android/widget/ExpandableListView.html) to group the "bus line". So you just need to manage only one adapter. –  Mar 07 '13 at 01:04
  • I am currently investigating this one. Also if you add this as an answer, I will tick as a solution if it really fix to my problem (It looks like it will) Thank you! – Onur Mar 07 '13 at 01:15

1 Answers1

0

You might want to use ExpandableListView to group the "bus line". So you just need to manage only one adapter.

  • ExpandableListView seemed complicated to me. Instead I created a method which will create and set an adapter. Also I remembered LazyAdapter and removed unnecessary parts in Adapter description. Why I used that way is also relative with the rest of my code. For many coders the bottom will be really helpful. Thank you, Lai! – Onur Mar 09 '13 at 03:58