简体   繁体   English

当我们在listview中点击列表行时,如何扩展列表行

[英]How to expand a list row when we tap on it in listview

In my app I have a Custom listview with some textviews and Image view like following image. 在我的应用程序中,我有一个自定义列表视图,其中包含一些textview和图像视图,如下图所示 在此输入图像描述

My requirement is when we tap on a list row it should expand and when tap on it again or tap on any other row it should collapse. 我的要求是当我们点击列表行时它应该展开,当再次点击它或点击任何其他行时它应该崩溃。 Expanded row should be like this 扩展行应该是这样的 在此输入图像描述

Contents of the expanded row is dynamic, some times no data and some times more values. 扩展行的内容是动态的,有时没有数据,有时是更多的值。 It should look like in the 2nd image. 它看起来应该像第二张图片。 Please give a solution for this. 请为此提供解决方案。

You are looking for ExpandableListView . 您正在寻找ExpandableListView

Expandable ListView bydefault has two levels. 可扩展的ListView bydefault有两个级别。 First is called the "Group View" and the second level is called the "Child View". 第一个称为“组视图”,第二个级别称为“子视图”。 You can simply achieve by making use of the Custom Adapter sample from the very first link I have provided. 您可以通过使用我提供的第一个链接上的Custom Adapter样本来实现。

here are few links which will get you started, 这里有一些链接可以帮助你入门,

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html

http://about-android.blogspot.in/2010/04/steps-to-implement-expandablelistview.html http://about-android.blogspot.in/2010/04/steps-to-implement-expandablelistview.html

http://www.techienjoy.com/android-expandable-list-dynamically-created-example.php http://www.techienjoy.com/android-expandable-list-dynamically-created-example.php

EDIT 1 编辑1

To make only child expanded at a particular time, add this, 要在特定时间仅扩展子项,请添加此项,

explist.setOnGroupExpandListener(new OnGroupExpandListener() {

    public void onGroupExpand(int groupPosition) {


        for(int i=0; i<myExpAdapter.getGroupCount(); i++) {
            if(i != groupPosition) {
                explist.collapseGroup(i);
            }
        }
    }

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM