2

I am using two ListView in same screen,Because of using two Listviews likely Parent ListView and Child ListView,that Child ListView Adapter class doesn't show all List Values in Child ListView.It showed only 0 th(first) position in Child ListView,for this above issue I have used the answer code from this Android list view inside a scroll view link.now I can see all list values in my Child ListView but It is not showing all my List values in same time which I had grabbed from Web service call.It showed first value only in list because the List View height was set to list's single item height.If I scroll down the Child ListView I am able to see all values in ListView.What I need is If i get five list values from Web service It has to show all five items in same time.

note: If I set hard coded values for List,It showed all items in Child ListView at one time.

Edited

How I achieved it using MergeAdapter

This createAdapter method would return Adapter object and I have set that Adapter into my Listview using setAdapter(createAdapter(new ArrayList<T>()))

 private ListAdapter createAdapter(List<T> items) {

        mergeAdapter = new MergeAdapter();
        mergeAdapter.addAdapter(endlessFeedAdapter);       

        return  mergeAdapter;
    }

What I need is

I Have been suggested to use ExpandableListView instead of using two ListViews. If I use ExpandableListView I will have to change the createAdapter method return type into ExpandableListAdapter for this I used below code

 private ExpandableListAdapter createAdapter(List<T> items) {

            mergeAdapter = new MergeAdapter();
            mergeAdapter.addAdapter(endlessFeedAdapter);       

            return (ExpandableListAdapter) mergeAdapter;
        }

but it showed the below Excaption

Caused by: java.lang.ClassCastException: com.commonsware.cwac.merge.MergeAdapter cannot be cast to android.widget.ExpandableListAdapter Values from Web service

enter image description here enter image description here

Hard coded values

enter image description here

Community
  • 1
  • 1
Jamal
  • 976
  • 2
  • 14
  • 39
  • If I'm understanding your setup correctly, I think you should be using an ExpandableListView, instead of trying to nest ListViews. – Mike M. Dec 18 '14 at 04:49
  • I had completed all my required things using these two `ListViews`.If I migrate to `ExpandableListView` it would take more time for implementation.according to my point of view any small changes in code will fix this. – Jamal Dec 18 '14 at 05:49
  • 2
    You are fighting an uphill battle man. Embedding two ListView's together does not work well with Android. It's a big no no. You should be using an `ExpandableListView`. Also, it's a huge performance hit when you embed an adapter inside another adapter. It may be a pain to migrate but that's the way to go. Otherwise, you'll just continue to hack up the code to get something to work that wasn't designed to work like that. – Ifrit Dec 19 '14 at 01:25
  • Just remove all this "code" what you have done, and start from zero with any tutorial from internet, e.g. http://www.coderzheaven.com/expandable-listview-android-simpleexpandablelistadapter-simple-example/ – Divers Jan 02 '15 at 09:32
  • 1
    My apologies for not responding to this sooner -- I did not get an email notification for it. I agree with the above comments, that having a `ListView` inside of a `ListView` is unlikely to work well. With regards to your `ClassCastException`, `MergeAdapter` is not an `ExpandableListAdapter`. You will need to implement your own `ExpandableListAdapter` -- see [this project](https://github.com/commonsguy/cw-omnibus/tree/master/WidgetCatalog/ExpandableListView) for an example of this. – CommonsWare Jan 03 '15 at 00:26
  • Once you get the data from the web service call, calculate the number of rows you need and programmatically set the height of the child ListView to be number of rows * height of one row. I can give you sample code if this is useful. – varsha-venkatesh Jan 06 '15 at 18:03

1 Answers1

2

What is stopping you to make 2 different adapters and adding them to MergeAdapter? You can add multiple adapters to MergeAdapter and multiple views. In that case there is no need to use 2 Listviews.

mergeAdapter.addAdapter(adapterHeading);
mergeAdapter.addView(someView);
mergeAdapter.addAdapter(adapterFooter);
listView.setAdapter(mergeAdapter);
Mikelis Kaneps
  • 4,576
  • 2
  • 34
  • 48