4

I have implemented Navigation Drawer by Referring this tutorial and now what I want to do is to display swiping tabs inside a fragment. ie. when i click on an item in navigation drawer, lets say the first one, it should display swiping tabs for that items.

If the item1 is Events, when i click on it, then it should display swiping tabs with tabs like todays events, and upcoming events. Im a beginner and I have tried to google for this, the solution i find is using sherlock, but i dont want to use any library. Please point me to a right tutorial. Can i implement view pager inside fragment. Given that view pager will have two more fragments.

Thank you.

Community
  • 1
  • 1
user3390703
  • 43
  • 1
  • 4
  • you don't need and perhaps shouldn't have a fragment in your navigation drawer - you can use a FragmentViewPager inside the layout for the drawer, and this could contain fragments, but please think about your UX design and ensure this is what you (/your users) want. – ataulm Mar 13 '14 at 20:21
  • Thats right.. if you use the drawer layout, and then set your child views, you can easily achieve what you are trying to do. – mike20132013 Mar 13 '14 at 21:34

1 Answers1

1

Here's one example of the drawer I was talking in that comment. If you have the drawer layout and the child as listview and viewpager, this is how the layout will look like:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#333333"
    tools:context=".MainActivity" >

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <!-- This List View for the sliding menu -->

    <LinearLayout
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:orientation="vertical" >
<!-- If you want to add some more things to your navigation drawer -->
        <!-- <EditText
            android:id="@+id/search_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:hint="Search"
            android:maxLines="1" >
        </EditText> -->

        <ListView
            android:id="@+id/list_slidermenu_child"
            android:layout_width="250dp"
            android:layout_height="match_parent"
            android:background="#303030"
            android:choiceMode="singleChoice"
            android:divider="#272727"
            android:dividerHeight="3dp"
            android:listSelector="@drawable/list_selector"
            android:padding="5dp" />
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

And this is how your layout will look like:

Test Image http://imageshack.com/a/img22/9166/qh8h.png

Now, in my example, When I click on any item in the list, the view pager sets that view it's supposed to be.

Is this how you want it to be ?

Here's a new image:

Test Image http://imageshack.com/a/img600/4421/2khw.png

And on click of any of the items in the navigation, it displays that content on the view behind it ?

mike20132013
  • 5,357
  • 3
  • 31
  • 41
  • Im trying to implement something like the google music player application. I want the navigation drawer items when clicked to take me to an activity instead of a fragment. When i do this, the activity launches but the navigation drawer dissappears. Can u please tell me how to make the navigation drawer as base class and use it in all my activities? – user3390703 Mar 15 '14 at 02:37
  • Can you just show like a rough sketch of the thing you are trying to do. I am also posting a new Image.. let me know if you want something like that. – mike20132013 Mar 15 '14 at 03:18
  • exactly, the above image is what I want. So when i click on My library, it should show swipe tabs like Music, Albums, Artists etc. – user3390703 Mar 15 '14 at 22:41
  • This is my answer I posted on your other post – mike20132013 Mar 15 '14 at 22:42
  • If this is what you want, its pretty simple.. both the images are same kind and share the code type.. I have the code for the first image you see here..I was waiting for your reply on the other post. – mike20132013 Mar 15 '14 at 22:43
  • could you please send me the code so that i can have a look at it? – user3390703 Mar 15 '14 at 22:54
  • yea sure, you can email me on addicted2.2speed@gmail.com and thank you very much. – user3390703 Mar 15 '14 at 22:56
  • Thank's for the email..It's better to send it in the email since the code is big.. don't forget to accept and upvote my answer .. ;) – mike20132013 Mar 15 '14 at 22:57
  • yea sure, Please let me knw when u send me the email. – user3390703 Mar 15 '14 at 23:03
  • No problem.. just few minutes.. I am making some change to the code since I am doing a different method. – mike20132013 Mar 15 '14 at 23:06
  • yea, you got me right? A navigation drawer with list, when i click on an item it takes me to swipe tabs with two fragments lets say, the second item when clicked takes me to another swipe tabs with five fragments or pages. I have been trying to implement this from three days. not finding anything on the internet. – user3390703 Mar 15 '14 at 23:15
  • This is not very hard though..m almost done with your code..that navigation drawer is amazing!! – mike20132013 Mar 15 '14 at 23:17
  • i have implemented the navigation drawer and i have implemented all the swipe tabs, but im not able to implement my actual idea. I just need to have a look at how it has to be done. Thanks for helping. – user3390703 Mar 15 '14 at 23:23
  • I am sorry its taking a bit long.. its just that i am changing some stuff for better understanding of code. – mike20132013 Mar 15 '14 at 23:35
  • its not a problem. Im waiting. – user3390703 Mar 15 '14 at 23:35
  • Sent you the zip..check you email and let me know if you got it.. sorry for the delay..:) – mike20132013 Mar 15 '14 at 23:58
  • Hey, I replied to your email with a question, please reply back to me. And i appreciate the help. – user3390703 Mar 16 '14 at 07:40
  • @mike20132013 I am also doing the same type of work.But, I am not able to get any proper output could you please send me the code..you can email me on amardeepvijay00@gmail.com and thank you very much. – Amardeepvijay May 15 '14 at 09:51
  • @Amardeep No problem.. Sharing is caring .. :D..:) What exactly are you trying to do ? Is it just like a list view with those custom items or its both list view with the view pager and navigation drawer as my image included in the answer? Let me know. – mike20132013 May 15 '14 at 13:50
  • @mike20132013 Hey mike im also facing the same issue. I implemented a navigation drawer with listView. When you click on each item it opens a fragment with few more listitems in it. Now what i want to implement is,when you click on single listitem inside fragment, there to be another activity display swipeable tabs layout. As ive been throw above comments felt like you got the solution for it. can you please mail me as well the code. IF not you any of the users received code from mike mail to my address please: Mail ID:laxmibhavisetti@yahoo.co.uk – Daya Jun 05 '14 at 11:57