0

我正在制作一个 webView 浏览器,我正在尝试制作一个向下滑动的按钮以显示更多按钮,我在下面显示了错误发生的代码,我还说明了错误发生在哪一行。提前致谢!

ExpandableListView expandableList = getExpandableListView(); *<-The method*             -   *getExpandableListView() is undefined for the type MainActivity IS THE ERROR I GET ON  -   THAT LINE*
(ExpandableListView) findViewById(R.id.list)

expandableList.setDividerHeight(2);
expandableList.setGroupIndicator(null);
expandableList.setClickable(true);

setGroupParents();
setChildData();

MyExpandableAdapter adapter = new MyExpandableAdapter(parentItems,childItems);

adapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),  -   this);
expandableList.setAdapter(adapter);
expandableList.setOnChildClickListener(this); *<-The method                                 -   setOnChildClickListener(ExpandableListView.OnChildClickListener) in the type            -   ExpandableListView is not applicable for the arguments (MainActivity) IS THE ERROR I   -   GET ON THAT LINE*
}
4

2 回答 2

0

我从来没有使用过ExpandableListView,但我敢肯定ListView,如果你不扩展,ExpandableListActivity那么你会得到那个错误。

View您需要在您的layoutthat is an中创建自己的,ExpandableListView或者您需要extends ExpandableListView在您的Activity中以这种方式使用它的方法和侦听器,例如getExpandableListView()

于 2013-10-01T19:59:44.053 回答
0

MainActivity 必须扩展 ExpandableListActivity。我怀疑你刚刚使用了一个活动。您必须提供声明您的活动的行。

expandableList.setOnChildClickListener() 采用 ExpandableListView.OnChildClickListener 类型的参数。在您提供的代码中,我没有看到您实例化了侦听器。如果您的活动声明还声明您实现了 ExpandableListView.OnChildClickListener 接口,我看不到 onChildClic() 的覆盖。

简而言之,你应该有

public class MainActivity extends 
    ExpandableListActivity implements ExpandableListView.OnChildClickListener {
    ...
    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int 
            groupPosition, int childPosition, long id) {
        ...
    }
    ...
}
于 2013-10-01T20:02:04.583 回答