简体   繁体   English

使用导航抽屉时是否必须使用碎片

[英]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.

相关问题 如何在不使用片段的情况下在导航抽屉中执行ExpandableListView? - how can I do ExpandableListView in navigation drawer without using fragments? 使用带有活动或片段的导航抽屉? - Use navigation drawer with activities or fragments? 使用导航抽屉未显示片段 - Fragments not showing using navigation drawer 如何在没有碎片的情况下使用导航抽屉? - How can I use the Navigation Drawer without fragments? 我正在尝试使用导航抽屉在活动之间切换,而不是片段 - I am trying to switch between activities using the navigation drawer, and not fragments 如何在导航抽屉(片段)上安装onbackpress - How to have onbackpress on navigation drawer(fragments) 当我使用提供Android Studio的活动抽屉导航模板时,如何使用片段在Drawerlayout上打开项目? - How can I use Fragments to open items on a Drawerlayout, when i used the Activity Drawer Navigation Template that provides android studio? 如何在导航抽屉中的片段中使用活动 - How to use Activities within fragments in Navigation Drawer 导航抽屉+ ViewPager-片段不显示 - Navigation drawer + ViewPager - fragments do not show 在导航抽屉中使用片段进行导航 - Navigation with fragments in navigation drawer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM