Comments (18)
- This is not possible now. But it's on the todo list.
- I will add an option for this.
For now make it like this:
MaterialSection section = this.newSection("Master 1", new MasterFragment(), false, menu);
section.setOnClickListener(new MaterialSectionOnClickListener() {
@Override
public void onClick(MaterialSection section, View v) {
drawer.onClick(section, v); // call the default onClick function
drawer.closeDrawer(); // close the drawer
}
});
- I added the new example under functionally. The newest version isn't online in the play store for now.
from advancedmaterialdrawer.
Hi,
Converted all the activities to fragment now but got another issue.
I am using SlidingTabs
in first section with BACKPATTERN_BACK_TO_START_INDEX
as BACKPATTERN, but when I press back from another section Fragment is not visible I get just tabs or some times both are gone blank screen comes.
What could be the cause?
from advancedmaterialdrawer.
I have no idea. I replace only the fragment. Maybe SlidingTabs saves some states, and there the problem comes from.
But it works right, if you press the section again and not the back button?
from advancedmaterialdrawer.
No, Section 1 loads tabs, then going to section 2 loads OK, clicking section 1 again everything blank.clicking section2 also blanks.
Even your fragmentintruction,dummyfragment are also gone in this process, so I dont think this is the issue with Slidingtabs(I mean one section loads cardview with dummyFrament, this also becomes blank, only card visible after navigating.)
So now After so much work in converting activities to fragment, I am stuck again , will need to be stick with new intent again?
Any better suggestion.
from advancedmaterialdrawer.
Post the link to the library. I will see what i can do.
from advancedmaterialdrawer.
I tried using these two libraries.
https://github.com/jpardogo/PagerSlidingTabStrip
https://github.com/neokree/MaterialTabs
I have first section1 using neokree tabs and going back to section1 from other section makes it blank sometimes even tabs are also gone.
package test;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import it.neokree.materialtabs.MaterialTab;
import it.neokree.materialtabs.MaterialTabHost;
import it.neokree.materialtabs.MaterialTabListener;
public class FragmentSectionTestTabs extends Fragment implements MaterialTabListener{
MaterialTabHost tabHost;
ViewPager pager;
ViewPagerAdapter adapter;
private String[] tabs = { "tab1", "tab2" };
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.test,container, false);
tabHost = (MaterialTabHost) view.findViewById(R.id.tabHost);
pager = (ViewPager) view.findViewById(R.id.pager);
// init view pager
adapter = new ViewPagerAdapter(getFragmentManager());
pager.setAdapter(adapter);
pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// when user do a swipe the selected tab change
tabHost.setSelectedNavigationItem(position);
}
});
// insert all tabs from pagerAdapter data
for (int i = 0; i < adapter.getCount(); i++) {
tabHost.addTab(
tabHost.newTab()
.setText(adapter.getPageTitle(i))
.setTabListener(this)
);
}
return view;
}
@Override
public void onTabSelected(MaterialTab tab) {
pager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabReselected(MaterialTab tab) {
}
@Override
public void onTabUnselected(MaterialTab tab) {
}
private class ViewPagerAdapter extends FragmentStatePagerAdapter {
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
public Fragment getItem(int index) {
return new FragmentInstruction();
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
return tabs[position];
}
}
}
test layout is same as neokree texttab layout except toolbar is removed from there.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<it.neokree.materialtabs.MaterialTabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="48dp"
app:materialTabsPrimaryColor="#009688"
app:accentColor="#ffc400"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tabHost" />
</RelativeLayout>
Please check thanks.
from advancedmaterialdrawer.
Sorry for the late response, i think i can test it tomorrow.
from advancedmaterialdrawer.
Thats OK., though I have completed my App but ran into new problem when using sliding menu.
I raised a issue there but got the solution to comment a method is SlidingMenu
class.
Meanwhile I tried manipulating your lib because the issue I was getting, was related to custom fragment and If I replaced a fragment(using your section) then there was no issue.
So I came up with a solution that we can have a ghost section not visible in drawer and we can trigger its onClick
like we do in jQuery
using performClick()
method available with View
.
Anyway, but I think you should have a method in your lib to check if drawer is open or not.
public boolean isDrawerOpen(){
return drawerLayout.isDrawerOpen(drawerViewGroup);
}
And yes, thanks for your time looking at bug related to SlidingTabs.
Thanks.
from advancedmaterialdrawer.
Thank you, I will add add a isDrawerOpen and isDrawerClose method.
from advancedmaterialdrawer.
Nice library madcyph3r.
I have a problem with the back button.
In my fragment a have this code
FragmentTransaction t = fragment.getSupportFragmentManager().beginTransaction();
FragmentDetailBoc detailBul = FragmentDetailBoc.newInstance(bulletins.get(getPosition()).getId());
t.replace(R.id.conteneur, detailBul);
t.addToBackStack(String.valueOf(FragmentCommuniques.newInstance()));
t.commit();
And In the Main Activity I have
this.setBackPattern(MaterialNavigationDrawer.BACKPATTERN_LAST_SECTION);
to handle the back button.
But when I'm in FragmentDetailBoc and I click the back button I go to another fragment not in FragmentCommuniques.
Do you any idea for this problem?
Thanks.
from advancedmaterialdrawer.
The issue with SlidingTabs is actually with ViewPager restoring fragment.
So here is the solution.
//instead of
adapter = new ViewPagerAdapter(getFragmentManager());
//use
adapter = new ViewPagerAdapter(getChildFragmentManager());
and in your FragmentStatePagerAdapter override this method.
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
// just overiding this will take care of the rest.
// no need to call super class method
}
Thanks for your time though.
BTW, you completely skipped neokree's implemetation for master child navigation.
I need to add few method from there to make it work with onBackPressed also.
Anyway,
Thanks for everything you did.
Bye.
from advancedmaterialdrawer.
Yeah, i have forked it before. So it does not have the same methods for this kind of navigation.
Can i add your solution to the wiki with your credits?
from advancedmaterialdrawer.
Yes, of course.
And I made your example app to work with Master Child Navigation as Neokree does.(Will post those changes if you want, though not tested with custom fragment.and in multipane
mode,hamburger
is not shown, not even in his example.)
BTW I need to clear one more thing.
When you replace a fragment
with new one, old one is removed. On back pressed,old one is recreated(and I assume that its not resumed but recreated, correct me if wrong) and Fragment Docs says that resuming a fragment will also start from onCreateView()
. I am using volley
lib to fetch data using server API call, so when fragment is recreated API is called again.
So my question is, is there a way to stop this?So that when i press back button, fragment should be visible(as it was before replacing) but should not call onCreateView
again.
I am just asking what will happen if we just show,hide fragment. Is there something to deal with memory then?
What I mean is for BACKPATTERN_BACK_TO_START_INDEX
we can check for its position and if it is startIndex(say 0) then just hide it and show other fragment(say 1) and then when user clicks on section 2
, fragment 1
should be removed but fragment 0 should be hidden and after back pressed current fragment is removed and fragment 0
should be visible without call to onCreteView()
.
Your Thought on this?Effect on memory?
from advancedmaterialdrawer.
You can override the onBackPressed() mehtod and set a boolean for back pressed. If this boolean true, you doesn't run your code.
Like this:
// In your activity
private boolean loadSectionBackClick = false;
@Override
public void onBackPressed() {
loadSectionBackClick = true;
super.onBackPressed(); // to start the choosen backpattern
}
// getter and setter
public boolean isLoadSectionBackClick () {
return loadSectionBackClick;
}
public void setLoadSectionBackClick (boolean loadSectionBackClick) {
this.loadSectionBackClick = loadSectionBackClick;
}
// your fragment:
public void onCreateView(...) {
boolean loadSectionBackClick = ((YourActivity) getActivity()).isLoadSectionBackClick();
if(!loadSectionBackClick) {
// your code for onCreateView
} else {
((YourActivity) getActivity()).setLoadSectionBackClick(false);
}
}
from advancedmaterialdrawer.
Can you post the changes for the master child navigation?
from advancedmaterialdrawer.
Sorry not checked before, sure will do it.
Should I paste here changes/ or complete java file?
from advancedmaterialdrawer.
Created a gist for you.
https://gist.github.com/thevirus20/755d255d6ee92d08b943
Changes done(As I saved this for myself so that after you update something I can make this changes for my project, no hard engineering just simple note for myself):
- added isDrawerOpen()
- added setCustomFragment(Fragment fragment, String title, MaterialSection section)
- added 3 new var - Line 152
- initialized them in initGlobalVars() - Line 282
- added listener toolbarToggleListener
- modified ActionBarDrawerToggle constructor with toolbar
- added setToolbarNavigationClickListener in contructor
- in loadmenuandFagment() added current fragment and title to child stack - line no 677
- added afterFragmentSetted()
- added setFragmentChild(Fragment fragment,String title)
- added setFragment(Fragment fragment, String title, Fragment oldFragment)
- added syncSectionsState()
- added call to afterFragmentSetted in onCLick of section
- added call to syncSectionsState
- added closeDrawer() in else of section onClick
- added else part for childfragment onBackPressed()
- added check for close drawer onBackPressed
- added setHomeAsUpIndicator(int) and setHomeAsUpIndicator(drawable)
- uncommented allowArrowAnimation()
- menu.clear() added in onPrepareOptionsMenu()
- modified onOptionsItemSelected()
- added if(actionBarToggle != null) in showActionBarMenuIcon()
One thing I found that, if using toolbar in actionBarToggle constructor, then your showActionBarMenuIcon()
doesn't work , thats why added method setHomeAsUpIndicator(int)
.
Hope you can use it in your lib as base for this type of navigation.
Thanks.
from advancedmaterialdrawer.
Example Activity also updated on gist.
from advancedmaterialdrawer.
Related Issues (20)
- RTL slide shod HOT 1
- Header title text font HOT 1
- Account photo is changed to color HOT 9
- retain selected fragment on rotation HOT 1
- Master Child Navigation - Update? HOT 1
- support navigation bar in different api levels
- Toolbar cut off HOT 6
- Crashes on API 10 HOT 1
- app:theme is now deprecated. Please move to using android:theme instead. HOT 1
- Color of divider for section bottom HOT 1
- how to change drawer icon? HOT 1
- how to change height of actionbar? HOT 1
- PreferenceFragment support HOT 2
- failed to resolve HOT 2
- Keep fragment on orientation change HOT 2
- ActionBarActivity is deprecated HOT 3
- change background color of ActionBar to primaryColor HOT 2
- ActionBar Style (Colors and background)
- Closed
- Customize Item Background Colour HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from advancedmaterialdrawer.