How to expand and collapse an item in listview

老子叫甜甜 提交于 2019-12-05 13:00:18

You only have to set the visibility of the second textview to View.GONE and View.VISIBLE when the user clicks the item. Implement an OnItemClickListener first. Using an ExpandableListView for this simple task is overkill.

In your OnItemClick handler:

            TextView textView = (TextView)arg1.findViewById(R.id.textView2);

            if ( textView.getVisibility() == View.GONE)             
                {
                //expandedChildList.set(arg2, true);
                textView.setVisibility(View.VISIBLE);
                }
            else
                {
                //expandedChildList.set(arg2, false);
                textView.setVisibility(View.GONE);
                }

You should use ExpandableListview instead of simple ListView.

Updated

Follow this tutorial and it will help you https://www.youtube.com/channel/UCbP2HeYGC3kfHjHLMPplZuQ he'll teach you how to use ListView using BaseAdapter and this will grow your confidence to implement ExpandableListView on your own..

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