Android ExpandableListView Parent with Button

后端 未结 1 1111
后悔当初
后悔当初 2021-01-05 16:40

I am trying to achieve something like this. The Expandable List consists of the names of certain categories and when a parent is clicked, it shows the list of all the childr

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-05 17:23

    Adding a button to the group view shouldn't be that difficult.

    I believe the below should work (although I don't have a project using an array backed ExpandableListView to test on).

    I don't know your group row layout, so I'll make one up here for reference purposes.

    group_layout.xml

    
        
        

    Then in your getGroupView method from your adapter:

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
        if (convertView == null) {
            View convertView = View.inflate(getApplicationContext(), R.layout.group_layout, null);
            Button addButton = (Button)convertView.findViewById(R.id.addButton);
    
            addButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    // your code to add to the child list
                }
            });
        }        
        TextView textView = (TextView)convertView.findViewById(R.id.text1);
        textView.setText(getGroup(groupPosition).toString()); 
        return convertView; 
    } 
    

    0 讨论(0)
提交回复
热议问题