Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

How to use Navigation Drawer inside Tabs menu.

OP Pouya_am

29th January 2014, 09:30 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: Jan 2014
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
29th January 2014, 11:04 PM   |  #2  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 337
 
346 posts
Join Date:Joined: May 2013
More
Quote:
Originally Posted by Pouya_am

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

That last sentence does not make sense I assume you mean from the Fragment?! Well to access the holding activity you need to add an interface to the Fragment which the activity will implement.

Am I understanding you correctly that have a horizontal ViewPager and one of the Fragments should have a Navigation drawer? To accomplish that you would still need the whole activity to hold the drawer and figure out a way to disable it when the user is on some other Fragment. But my question is why you want to use a navigation drawer in that case, because the drawer is meant for navigating on the same hierarchical level, but the different items are more independent than with the ViewPager. It doesn't really make sense to have both a drawer and horizontal swiping, even the YouTube app really bothers me with its swiping between suggestions and feed. I think what you need to use here is a spinner in the ActionBar, replacing the title of the Fragment.
29th January 2014, 11:15 PM   |  #3  
OP Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: Jan 2014
Quote:
Originally Posted by SimplicityApks

That last sentence does not make sense I assume you mean from the Fragment?! Well to access the holding activity you need to add an interface to the Fragment which the activity will implement.

Am I understanding you correctly that have a horizontal ViewPager and one of the Fragments should have a Navigation drawer? To accomplish that you would still need the whole activity to hold the drawer and figure out a way to disable it when the user is on some other Fragment. But my question is why you want to use a navigation drawer in that case, because the drawer is meant for navigating on the same hierarchical level, but the different items are more independent than with the ViewPager. It doesn't really make sense to have both a drawer and horizontal swiping, even the YouTube app really bothers me with its swiping between suggestions and feed. I think what you need to use here is a spinner in the ActionBar, replacing the title of the Fragment.

Yeah you're right , I just want to use the drawer in order to change contents.
So as you suggest , I just have to use a simple tricks to make the drawer enable in desire Fragment.
I don't want to , I am asked to make it possible....
Last edited by Pouya_am; 30th January 2014 at 06:54 AM.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes