【问题标题】:Expand Expandable Listview in android on button Click在 android 中展开 Expandable Listview on button Click
【发布时间】:2014-05-28 03:03:58
【问题描述】:

我正在使用其自定义适配器实现可扩展列表视图。 group 元素需要有 2 个按钮,第一个作为父 group 元素,下面有一个按钮。

我的问题是,我想在单击下面的按钮而不是 group 元素时展开列表视图。此外,组元素onClick 需要调用另一个活动。

我可以通过

禁用expandablelistview的扩展
mainExpListView.setOnGroupClickListener(new OnGroupClickListener() {

    @Override
    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) 
    {   

        return false;
    }

所以我的问题:

  1. 有没有办法禁用组元素并让它执行其他功能(比如导航到另一个活动?)

  2. 如何在底部图片上设置onclick方法来展开?

【问题讨论】:

  • 你的问题对我来说有点不清楚。如果您想在按下按钮时扩展组,那么您可以执行类似list_expandable.expandGroup(position); 的操作。其中position 是该组在列表中的索引,索引从零开始。

标签: android expandablelistview


【解决方案1】:
 this is the groupview of my adapter and expand is the button on which i am performing  expand and collapse of my expanded list.



    public View getGroupView(final int groupPosition, final boolean isExpanded,
                             View convertView, final ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.childlist_group, null);
        }

        TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
        ImageView expand = (ImageView) convertView.findViewById(R.id.expand);
        if (isExpanded) {
            expand.setImageResource(R.mipmap.ic_star_selected);
        } else {
            expand.setImageResource(R.mipmap.ic_keyboard_arrow_right_black_24dp);
        }
        expand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // frag.expandandcollapse(isExpanded,groupPosition);
                if (isExpanded) ((ExpandableListView) parent).collapseGroup(groupPosition);
                else ((ExpandableListView) parent).expandGroup(groupPosition, true);
            }
        });
        lblListHeader.setText(headerTitle);


        return convertView;
    }


therefore one more thing to keep in mind u have to override the default expand and collapse of your expandedlistview.........just change the return type of on groupclick listner from false to true


example
ExpandableListView.OnGroupClickListener()
 {
            @Override

            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) 
{


                String groupNvalue = MyApp.getInstance().categoryNvalues.get(groupPosition);
                Showtoast(groupNvalue);

                return true;///this has to be changed to true in your activity or fragment
            }
        });

【讨论】:

    【解决方案2】:

    我不确定,但是 在适配器中,您可以在视图上设置点击侦听器

    @Override
    public View getGroupView(int pos, boolean arg1, View convertView, ViewGroup arg3) {
    
    if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) act
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.drawerlayout, null);
        }
          convertView.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
    
            }
        })
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      相关资源
      最近更新 更多