Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageButton on Expandablelistview child item

Is it possible to have a clickable ImageButton on Expandablelistview child item? If yes, how to program its event listener?

like image 954
user371801 Avatar asked Feb 27 '23 19:02

user371801


1 Answers

In your Adapter, override the getChildView method. Inflate a custom layout for the child view which contains the button. Find the button view and set the listener. You may want/need to override a few of the other Adapter methods as well.

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
            View convertView, ViewGroup parent) {

        View v = mInflater.inflate(R.layout.expander_child, null);

        Button button = (Button)v.findViewById(R.id.expand_child_button);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(ExpandableList1.this, "button pushed", Toast.LENGTH_SHORT).show();
            }
        });         
        return v;
    }
like image 180
Daddyboy Avatar answered Mar 08 '23 03:03

Daddyboy