我试图在导航抽屉中创建一个ExpandableListView。我尝试了一个示例代码,但在编译之前得到了这个错误。
public class MainActivity extends Activity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.left_drawer);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);错误在这一行中: listAdapter =( this,listDataHeader,listDataChild);
为什么它说不能实例化类型ExpandableListAdapter?
发布于 2013-10-21 12:38:18
ExpandableListAdapter也是android.widget.ExpandableListAdapter中的一个接口,您似乎正在导入它,这是试图实例化本地ExpandableListAdapter类。
重命名你的ExpandableListAdapter。
发布于 2015-08-19 10:42:05
删除import android.widget.ExpandableListAdapter;或用此名称重命名类。
:)
发布于 2013-10-21 12:36:06
因为ExpandableListAdapter是一个interface,所以aka没有实现。
查看文档,了解ExpandableListAdapter的一些实现,如SimpleExpandableListAdapter。
https://stackoverflow.com/questions/19494572
复制相似问题