因此,我在这里搜索了有关导航抽屉的分配,当我从另一个人的问题的答案中找到教程时。我就这么做了。
我成功地根据自己的喜好创建了导航抽屉并设计了其样式。
但现在我一直在不知疲倦地寻找如何从导航抽屉启动活动。我已设法将一些代码放入 MainActivity 中,但单击该项目后它不会启动任何内容?所有活动都在清单中定义。我决定使用 Toasts 作为尝试和错误,但仍然没有运气。
这是我的导航抽屉和启动活动的代码。
// Drawer Activity
// Get list items from strings.xml
drawerListViewItems = getResources().getStringArray(R.array.items);
// Get ListView defined in activity_main.xml
drawerListView = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
drawerListView.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_listview_item, drawerListViewItems));
// Run Activity from drawer
drawerListView.setOnItemClickListener(new DrawerItemClickListener());
这是我的 DrawerItemClickListener 方法
private class DrawerItemClickListener implements ListView.OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position) {
case 0:
Intent a = new Intent(this, AppInfo.class);
startActivity(a);
break;
case 1:
Intent b = new Intent(getBaseContext(), WelcomeActivity.class);
startActivity(b);
}
}
}
Repalce this
with MainActivity.this
像那样:
Intent a = new Intent(MainActivity.this, AppInfo.class);
startActivity(a);
也改变一下
drawerListView.setOnItemClickListener(new DrawerItemClickListener());
replace
drawerListView.setOnItemClickListener(this);
检查那里定制适配器 https://stackoverflow.com/questions/23485986/custom-adapter-for-a-list-of-items-that-have-multiple-child-items/23486051#23486051
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)