简体   繁体   中英

setOnChildClickListener of expandablelistview doesn't take action

I am newbie to android development .

My goal to make an Expandable List view and on each child of a group of that expandable

list view I want to set an event when that child clicked.

So I have downloaded a ready android project from here .

http://mylifewithandroid.blogspot.com/2011/06/hiding-group-indicator-for-empty-groups.html

and run it by eclipse IDE .

在此处输入图片说明

I add this code to ExpList3 class to test an event.

but no event gained when press any child of a list view group

getExpandableListView().setOnChildClickListener(new OnChildClickListener()
            {
            @Override
            public boolean onChildClick(ExpandableListView arg0, View v,
                        int groupPosition, int childPosition, long id) {

                    if(groupPosition==0&&childPosition==0 )
                    {
                        TextView myTextView = 
                                 (TextView)findViewById(R.id.groupname);
                                 myTextView.setText("Text Changed");
                    }

                    else if(groupPosition==0&&childPosition==1)
                    {
                        TextView myTextView = 
                                 (TextView)findViewById(R.id.groupname);
                                  myTextView.setText("Text Changed");
                    }   
                    else if(groupPosition==1&&childPosition==0&&id==0)
                    {
                        TextView myTextView = 
                                 (TextView)findViewById(R.id.groupname);
                                 myTextView.setText("Text clicked");    

                    } 
                    return false;

                }

            });

You have used a textview and setting clicked list item in the textview. Use Toast to view the clicked item. Also location of the textview matters in displaying your clicked item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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