且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在列表视图中展开和折叠项目

更新时间:2023-12-02 18:37:58

用户单击项目时,只需将第二个文本视图的可见性设置为View.GONE和View.VISIBLE.首先实现一个OnItemClickListener.为这个简单的任务使用ExpandableListView是过分的.

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.

在您的OnItemClick处理程序中:

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