[英]Do i have to use fragments when using navigation drawer
I am currently building an app, and have decided to implement a navigation drawer for ease of use. 我目前正在构建一个应用程序,并决定实现一个易于使用的导航抽屉。 currently, nearly all my classes extend activity, however, looking at the navigation drawer examples, they all use fragments.
目前,我的几乎所有类都扩展了活动,但是,查看导航抽屉示例,它们都使用片段。 do I have to use fragments for this, or can i keep my classes as activities?
我必须为此使用片段,还是可以将我的课程作为活动? I am only worried, as I have nearly finished the app, and have been told that they do not use the same methods.
我只是担心,因为我几乎完成了应用程序,并被告知他们不使用相同的方法。
No. you can acheive with Activity. 不,你可以用Activity来实现。 Not required to use Fragment.
不需要使用Fragment。 http://developer.android.com/training/implementing-navigation/nav-drawer.html
http://developer.android.com/training/implementing-navigation/nav-drawer.html
Read this reference , this has detail about Drawer layout. 阅读此参考,这里有关于抽屉布局的详细信息。
Create a Base class called DrawerBaseActivity which extends Activity. 创建一个名为DrawerBaseActivity的Base类,它扩展了Activity。 Add all the drawer code to DrawerBaseActivity and Make all your custom activity extends DrawerBaseActivity.
将所有抽屉代码添加到DrawerBaseActivity并使所有自定义活动扩展DrawerBaseActivity。
The link reference ask you to replace the fragment on drawerItemClick. 链接引用要求您替换drawerItemClick上的片段。 But instead of fragment replace create intent to an activity and start your activity.
但是,而不是片段替换创建活动的意图并开始您的活动。
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
switch (position)
{ case 1 :
// start your respective activity
}
}
}
To keep the rich UI feature you would be better off using fragments. 要保留丰富的UI功能,最好使用片段。
If you have trouble calling methods you can always call 如果您在调用方法时遇到问题,可以随时致电
getActivity( ).TheMethod ( )
That will use the parent activity to call the relevant methods for you. 这将使用父活动为您调用相关方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.