expandablelistview的setOnChildClickListener不执行操作

时间:2014-03-10 11:01:18

标签: android eclipse expandablelistview

我是android开发的新手。

我的目标是制作可扩展列表视图以及可扩展

组的每个子项

列表视图我想在点击该子项时设置一个事件。

所以我从这里下载了一个现成的android项目。

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

并通过eclipse IDE运行它。

enter image description here

我将此代码添加到ExpList3类以测试事件。

但是按下列表视图组中的任何子项时都没有获得任何事件

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;

                }

            });

1 个答案:

答案 0 :(得分:0)

您在textview中使用了textview并设置了单击列表项。使用Toast查看单击的项目。此外,textview的位置在显示您点击的项目时也很重要。