How do I use the parameter defined in another class? - android

I am using a navigation drawer in my main activity defined as
private DrawerLayout drawerlayout;
I am using it in main activity to open and close my nav fragment, but there are 3 specific buttons in nav fragment class where I would like to use the nav fragment functionality drawerlayout.closedrawer(r.id.drawer)
But everytime I define it again in nav fragment class and try to add it in the onclick for these buttons, upon clicking the buttons, the app crashes with a nullpointer exception.How do I go about the same?
Thanks!
Here's the sample code from my app:
public class navfragment extends fragment {
public interface OnCloseDrawerListener
{
void onCloseDrawer();
}
#Override
public void onClick(final View v) {
switch (v.getId()) {
case R.id.button_logout:
final DialogFragment dialog = new LogoutCancelSignoutDialogFragment(mLogoutListener);
dialog.show(getActivity().getSupportFragmentManager(), AbsBaseaActivity.TAG_LOGOUT_DIALOG);
BangoHelper.eventLogout();
((OnCloseDrawerListener)getActivity()).onCloseDrawer();
break;
}
}
In my class MainActivity:
public class MainActivity extends AbsBaseaActivity implements OnBackStackChangedListener {
private DrawerLayout drawerLayout;
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
//----------Code for Navigation Drawer setup
// 2. App Icon
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// 2.1 create ActionBarDrawerToggle
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.drawable.arrow_up, R.string.drawer_open, R.string.drawer_close){
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
// getActionBar().setTitle(NavigationPanelFragment.activeFragmentTitle);
// invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
// getActionBar().setTitle(NavigationPanelFragment.activeFragmentTitle);
// invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
// 2.2 Set actionBarDrawerToggle as the DrawerListener
drawerLayout.setDrawerListener(actionBarDrawerToggle);
}
public void onCloseDrawer()
{
drawerLayout.closeDrawer(R.id.drawer);
}
Even after modifying the code as per the given suggestion it crashes when I click on the button defined onclick for the fragment class, any clue?

You could add a callback from your fragment to your activity to close the drawer..
Ex.
public class YourFragment extends Fragment
{
public void onClick(View v)
{
((OnCloseDrawerListener)getActivity()).onCloseDrawer();
}
public interface OnCloseDrawerListener
{
void onCloseDrawer();
}
}
Then in your activity you would need to implement this interface
public class MyActivity extends Activity implements OnCloseDrawerListener
{
#Override
public void onCloseDrawer()
{
// add whatever code you need to close the drawer
}
}
Obviously you can name this interface something that more accurately represents your needs and pass it whatever arguments you require

Related

How can i open the main navigation drawer programmatically from inside the attached fragment?

I have created a navigation drawer activity and I want to remove the toolbar of the activity and use the custom toolbar in different fragments, now I can't find any way to open and close the navigation drawer from inside the fragment.
Like in main navigation activity the drawer can be open and closed on the click of the hamburger menu, but how can I open the drawer from the attached fragment to it.
Use custom listener:
class Frag extends Fragment{
NavigationOpenListener listener;
public interface NavigationOpenListener{
public void OnDrawerOpen();
}
public void openDrawer(){ // Call this method when you want to open drawer from your Fragment
if(listener!=null)
listener.OnDrawerOpen();
}
public void setOnDrawerOpenListener(NavigationOpenListener onDrawerOpenListener){
this.listener=onDrawerOpenListener;
}
}
And listen on your Activity:
Frag frag1=new Frag();
frag1.setOnDrawerOpenListener(new Frag.NavigationOpenListener() {
#Override
public void OnDrawerOpen() {
yourDrawerLayout.openDrawer(GravityCompat.START);
}
});
First of all create static instance of navigation drawer activity and then call public method of change fragment from your fragment like following
public class MainActivity extends AppCompatActivity
{
static MainActivity instance;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
instance=this;
}
public static MainActivity getInstance()
{
return instance;
}
public void changeFragment(Fragment targetFragment)
{
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fl_main_container, targetFragment, "fragment")
.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
}
From Fragment call method like following
MainActivity mainActivity=MainActivity.getInstance();
mainActivity.changeFragment(new FragmentHome());

How to show default tab when Resumed to activity?

I have an activity in which I have Tablayout and have two tab named as "Deal","Story" when I navigate to other activity and again resume to that activity
then that tab was appears which I had viewed earlier,while I want whenever I resumed to that activity always show default tab .How can I DO THAT
code:-
public void init() {
s_oCloginSession = new CLoginSessionManagement(CMainActivity.this);// object creation of Login Session...
setupToolbar();// setting toolbar
// navigation bar code
m_Drawer = (DrawerLayout) findViewById(R.id.drawer_layout);//finding id of drawerlayout
s_drawerToggle = new ActionBarDrawerToggle(
this, m_Drawer, m_Toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
m_Drawer.setDrawerListener(s_drawerToggle);
m_Drawer.setScrimColor(getResources().getColor(android.R.color.transparent));
s_drawerToggle.syncState();
NavigationView m_Navigation = (NavigationView) findViewById(R.id.nav_view);
m_Navigation.setNavigationItemSelectedListener(this);
m_TabLayout = (TabLayout) findViewById(R.id.tab_layout);// finding Id of tablayout
m_TabLayout.addTab(m_TabLayout.newTab().setText("Deals"));// add deal listin tab
m_TabLayout.addTab(m_TabLayout.newTab().setText("Stories"));// add stories tab
m_TabLayout.setTabGravity(TabLayout.GRAVITY_FILL);// setting Gravity of Tab
m_ViewPager = (ViewPager) findViewById(R.id.pager);//finding Id of ViewPager
CDealMainListingPager m_oDealMainScreenPager = new CDealMainListingPager
(getSupportFragmentManager(), m_TabLayout.getTabCount());
m_ViewPager.setAdapter(m_oDealMainScreenPager);// adiing adapter to ViewPager
m_ViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(m_TabLayout));// performing action of page changing
m_TabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
m_ViewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
You can create one class named BaseActivity which extends AppCompatActivity. All your activity will now extend to this BaseActivity class instead of AppCompatActivity. So whenever you have not defined onBackPressed it will call it's parent class method and perform it's operations.
public class BaseActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.translate, R.anim.left_to_right_simple);
}
}
If you want to customise this method for one class then just need to override this method in that respective class. For other classes it will work same as defined in BaseActivity
Your all activity will be something like this.
public class HomeScreen extends BaseActivity{
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
Make a class, say CommonMethods and put the method into that class:
public class CommonMethods extends AppCompatActivity {
/*This method functions when user press device back button*/
#Override
public void onBackPressed() {
long currentTime = System.currentTimeMillis();
if ((currentTime - lastPressTime) < 2000) {
// Double Press
moveTaskToBack(true);
} else {
Toast.makeText(this, "Press again to exit", Toast.LENGTH_SHORT).show();
lastPressTime = currentTime;
}
}
}
Here, you can make this class extend Activity or AppCompatActivity based on your needs.
Finally, you can make the activity classes which need this feature, extend this CommonMethods class.
You can do this by taking one common class and implement this function in it,
Check below code,
Take one common class for method
//Here I am taking it as common class you can take it as per your choice
CommonClass.java
public class CommonClass
{
public bool manageBackPressed(Activity activity, long lastPressTime)
{
long currentTime = System.currentTimeMillis();
if ((currentTime - lastPressTime) < 2000) {
return true;
} else {
return false;
}
return false;
}
}
Now below check your onBackPressed method in any activity
#Override
public void onBackPressed() {
if(commonClass.manageBackPressed(this, lastPressTime))
{
moveTaskToBack(true);
}
else
{
Toast.makeText(this, "Press again to exit", Toast.LENGTH_SHORT).show();
lastPressTime = System.currentTimeMillis();
}
}
I think your previous thread will also work in background please cancel it when you dont want to update.

How do I change from one fragment or activity to another fragment or activity while using a NavigatorDrawer?

Sorry, but my question is more complex than what I have asked. I am new to Java and Android, and this whole NavigationDrawer thing is beating me down, but I am determined to figure it out. I downloaded the sample code from Android with nav drawer example, and I have deleted and added minor changes to fit preferences. Basically, using the code provided to me, I cannot figure out how to change to a different activity/fragment. Should I use another fragment like the example has shown or do I need to create a new Java class that extends an intent and create the corresponding xml layout? Once that is determined, do I create a switch case in the fragment class that was created to cycle through its corresponding fragment/activity? Or do I place a switch case in the selectItem() method? I have been working on this same problem for 8 days now and have finally decided to ask for help after exhausting all of my resources. Thanks for any help. Again, I'm not looking for someone to code for me, I only need help in understanding the questions I have asked and where my code will need to be placed.
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] choices;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
choices = getResources().getStringArray(R.array.choices_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, choices));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// enable ActionBar app icon to behave as action to toggle nav drawer
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
/* Called whenever we call invalidateOptionsMenu() */
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content view
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action buttons
/*
switch(item.getItemId()) {
case R.id.action_websearch:
// create intent to perform web search for this planet
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
// catch event that there's no activity to handle intent
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
}
return true;
default:
return super.onOptionsItemSelected(item);
}*/
return super.onOptionsItemSelected(item);
}
/* The click listener for ListView in the navigation drawer */
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
// update the main content by replacing fragments
Fragment fragment = new ChoicesFragment();
Bundle args = new Bundle();
args.putInt(ChoicesFragment.ARG_CHOICES_NUMBER, position);
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(choices[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggle
mDrawerToggle.onConfigurationChanged(newConfig);
}
/**
* Fragment that appears in the "content_frame", shows its appropriate layout
*/
public static class ChoicesFragment extends Fragment {
public static final String ARG_CHOICES_NUMBER = "planet_number";
public ChoicesFragment() {
// Empty constructor required for fragment subclasses
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.image_view_fragment, container, false);
int i = getArguments().getInt(ARG_CHOICES_NUMBER);
String available_choices = getResources().getStringArray(R.array.choices_array)[i];
int imageId = getResources().getIdentifier(available_choices.toLowerCase(Locale.getDefault()),
"drawable", getActivity().getPackageName());
((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId);
getActivity().setTitle(available_choices);
return rootView;
}
}// end ChoicesFragment class
}// end MainActivity
Looking at the code you posted (I can't compile it and try it now), I believe the intention of the sample is to use fragment when a choice is selected on the navigation drawer. Then you would put a case statement in selectItem() to determine which fragment should be shown.
So for example, if you have two choices (say "Show Red Colour" and "Show Blue Colour"), you would create a "RedFragment" class extending "ChoicesFragment", and a "BlueFragment" class extending "ChoicesFragment". Each of them would use their own XML layout. You can then create a fragment object (say "redFragment" and "blueFragment") for each of them in the onCreate() method.
Then, in the selectItem() method, you have a if/case statement to say if position is 0, then you would show the red fragment with:
...
fragmentManager.beginTransaction().replace(R.id.content_frame, redFragment).commit();
...
and similarly for blue fragment.
HTH.
Looks like you have some problem understanding abstraction levels and i will try to help with that.
Activities are entry points for your app, top level. The best approach is to use fragments and not activites, since fragments are at a lower level of abstraction, fragments are just pieces of activities.
Build all of your views in fragments and then put them on an activity, unless you really need a bigger level of abstraction depending on what your application does.
I do not see the need to create a class extending intent, etc. etc.
what i would is to add the navigation drawer as a fragment and put it in an activity, and the rest of the app should be fragments as well handled by the navigation drawer.
Or the navigation drawer can be part of the activity and the rest of the views fragments that depend from this activity.
Hope this helps to clear your mind.. sorry for not sharing code.. good luck

Navigation Drawer with Activities - Basic Concept

I have one basic question that I couldn't get hold in last couple of days (even after many example/explanation in googling and SOing).
I have 5 different Activity , each activity is independent of others, and each activity has it’s own layout file. Now, I want to add Navigation Drawer as my App Menu.
What i understand, 2 recommended ways are:
1) To merge those 5 activities into one MainActivity, and use 5 fragments to load 5 different layout. But it will be a hard for me to merge those 5 into 1. And won't there be any performance issue if I have all methods loaded in one Activity?
2) To have one BaseActivity containing drawer, and extend all other activity to Base Activity. But I have all my Activities extended to NavDrawer class (which contains drawer), but not working. Individually drawer is working fine (when I run NavDrawer only). Do I need to make any change to the layout xmls of my existing activities?
I am sorry if this is pretty much basic, but I am posting this after I failed to get hold the concept in 2 days!
I can attach my code if you want, but the drawer code is sort of basic thing, as per tutorial.
Thanks,
References I am using:
1) http://developer.android.com/training/implementing-navigation/nav-drawer.html
2) http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
I can suggest you to use ViewPager with actionbar tabs. Because with the help of viewpager, the same navigation draawer is visible for all the five fragments. Coming to the efficiency, ViewPager creates current page, besides it always prepares your next and previous pages also. So that it can be bit fast in showing the content while the user swipes pages. I always follow the same and I don't think it's inefficient.
Code snippet of one of my applications is below:
public class MainActivity extends ActionBarActivity {
String[] titles;
ViewPager viewPager;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mListTitles;
public PagerTabStrip titleStrip;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
viewPager = (ViewPager) findViewById(R.id.pager);
TitleAdapter titleAdapter = new TitleAdapter(getSupportFragmentManager());
viewPager.setAdapter(titleAdapter);
viewPager.setCurrentItem(0);
mTitle = mDrawerTitle = getTitle();
mListTitles = getResources().getStringArray(R.array.drawerlist_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// sets up the drawer's list view with items and click listener
mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mListTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// enables ActionBar app icon to behave as action to toggle nav drawer
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
)
{
public void onDrawerClosed(View view)
{
getSupportActionBar().setTitle(mTitle);
}
public void onDrawerOpened(View drawerView)
{
getSupportActionBar().setTitle(mDrawerTitle);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null)
{
selectItem(0);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onPrepareOptionsMenu(Menu menu)
{
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected(item))
{
return true;
}
else{
return false;
}
}
class TitleAdapter extends FragmentPagerAdapter{
private String titles[] = new String[]{"Expenses","Savings","Income"};
private Fragment frags[] = new Fragment[titles.length];
public TitleAdapter(FragmentManager fm) {
super(fm);
frags[0] = new Fragment1();
frags[1] = new Fragment2();
frags[2] = new Fragment3();
}
#Override
public CharSequence getPageTitle (int position){
Log.v("TitleAdapter - getPageTitle=", titles[position]);
return titles[position];
}
#Override
public Fragment getItem(int position) {
Log.v("TitleAdapter - getItem=", String.valueOf(position));
return frags[position];
}
#Override
public int getCount() {
return frags.length;
}
}
/* The click listner for ListView in the navigation drawer */
private class DrawerItemClickListener implements ListView.OnItemClickListener
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
selectItem(position);
}
}
private void selectItem(int position)
{
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mListTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
#Override
public void setTitle(CharSequence title)
{
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
#Override
protected void onPostCreate(Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
}

Change drawer icon back to back arrow

I'm using the new DrawerLayout to have side navigation. I'm using the drawer icon (the 'hamburger') like this:
#Override
protected void onStart() {
super.onStart();
mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main_drawerlayout);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_navigation_drawer,
R.string.app_name,
R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
However, when I add a Fragment to the backstack, I want to display the back arrow again, so the user can navigate back to "home", and only then open the app drawer.
How can I reset the drawer icon to the back icon?
The arrow I want:
To disable and hide the DrawerToggle "Hamburger", just call
mDrawerToggle.setDrawerIndicatorEnabled(false);
I created an interface for the hosting activity to update the view state of the hamburger menu. For top level fragments I set the toggle to true and for fragments for which I want to display the up < arrow I set the toggle to false.
public class SomeFragment extends Fragment {
public interface OnFragmentInteractionListener {
public void showDrawerToggle(boolean showDrawerToggle);
}
private OnFragmentInteractionListener mListener;
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
this.mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
}
}
#Override
public void onResume() {
super.onResume();
mListener.showDrawerToggle(false);
}
}
Then in my Activity ...
public class MainActivity extends Activity implements SomeFragment.OnFragmentInteractionListener {
private ActionBarDrawerToggle mDrawerToggle;
public void showDrawerToggle(boolean showDrawerIndicator) {
mDrawerToggle.setDrawerIndicatorEnabled(showDrawerIndicator);
}
}

Categories

Resources