mercredi 29 janvier 2014

How to use Navigation Drawer inside Tabs menu. topic




Hi guys.

I've been developing an app which has Swipeable menu in bottom and one of the pages , should have a Navigation Drawer to change its own Fragments.

MainActivity.java

Code:


package com.example.elizehprotowithshlkandvpis;

import com.example.elizehprotowithshlkandvpis.adapter.MainMenuAdapter;
import com.viewpagerindicator.TabPageIndicator;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class MainActivity extends FragmentActivity {
        private static final String[] CONTENT = { "Home", "AboutUs", "Maps", "Resturants", "Tours", "CustomerClub", "Neccesseries", "UrgentCall" };
        private ViewPager mViewPager;
        private FragmentPagerAdapter adapter;
       
        @Override
        protected void onCreate(Bundle savedInstanceState) {
               
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
               
                adapter    = new MainMenuAdapter(getSupportFragmentManager());
                mViewPager = (ViewPager) findViewById(R.id.pager);
                mViewPager.setAdapter(adapter);
               
                TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
                indicator.setViewPager(mViewPager);
               
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.main, menu);
                return true;
        }
       
        public static String[] getCONTENT() {
                return CONTENT;
        }

}


MainMenuAdapter.java

Code:


package com.example.elizehprotowithshlkandvpis.adapter;

import com.example.elizehprotowithshlkandvpis.MainActivity;
import com.example.menuclasses.AboutUs;
import com.example.menuclasses.CustomerClub;
import com.example.menuclasses.Maps;
import com.example.menuclasses.Neccesseries;
import com.example.menuclasses.Tours;
import com.example.menuclasses.UrgentCall;
import com.example.menuclasses.Resturants;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class MainMenuAdapter extends FragmentPagerAdapter {
        private static final String[] CONTENT = { "Home", "AboutUs", "Maps", "Resturants", "Tours", "CustomerClub", "Neccesseries", "UrgentCall" };

        private final int HOME_INDEX              = 0;
        private final int ABOUTUS_INDEX      = 1;
        private final int MAPS_INDEX              = 2;
        private final int RESTURANTS_INDEX  = 3;
        private final int TOURS_INDEX        = 4;
        private final int CUSTOMERCLUB_INDEX = 5;
        private final int NECCESSERIES_INDEX = 6;
        private final int URGENTCALL_INDEX  = 7;
        private final int NUMBEROFMENUS            = CONTENT.length;
       
        public MainMenuAdapter(FragmentManager fm) {
                super(fm);
                // TODO Auto-generated constructor stub
        }

    @Override
    public CharSequence getPageTitle(int position) {
        String[] CONTENT = MainActivity.getCONTENT();
            return CONTENT[position % CONTENT.length].toUpperCase();
    }

       
        @Override
        public Fragment getItem(int index) {
                switch(index) {
                case HOME_INDEX:
                        return new AboutUs();
               
                case ABOUTUS_INDEX:
                        return new AboutUs();
               
                case MAPS_INDEX:
                        return new Maps();
               
                case RESTURANTS_INDEX:
                        return new Resturants();
               
                case TOURS_INDEX:
                        return new Tours();
               
                case CUSTOMERCLUB_INDEX:
                        return new CustomerClub();
               
                case NECCESSERIES_INDEX:
                        return new Neccesseries();
               
                case URGENTCALL_INDEX:
                        return new UrgentCall();
                }
                return null;
        }


        @Override
        public int getCount() {
                // TODO Auto-generated method stub
                return NUMBEROFMENUS;
        }

}


The Fragment that should contain a Navigation Drawer is Resturants , also drawer's mainactivity is implemented with Sherlock Library(SherlockFragmentActivity).
I'm puzzled how to call the SherlockFragmentActivity from the SherlockActivity :)

Thanks





Aucun commentaire:

Enregistrer un commentaire