How to show All list items in child ListView-using cwac-merge-1.0.4 jar

╄→尐↘猪︶ㄣ 提交于 2019-12-24 02:43:45

问题


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

Hard coded values


回答1:


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);


来源:https://stackoverflow.com/questions/27539400/how-to-show-all-list-items-in-child-listview-using-cwac-merge-1-0-4-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!