Giter VIP home page Giter VIP logo

Comments (9)

madcyph3r avatar madcyph3r commented on August 17, 2024

In this library the first section must not be a fragment. It will load the first fragment it finds or you can defined the start section. Or you set an custom start fragment.

If you want to select the section with an activity, do following:

// make an section , without an intent and add an on click listener

yourSection.setOnClickListener(new MaterialSectionOnClickListener() {
            @Override
            public void onClick(MaterialSection section, View view) {
                drawer.getCurrentSection().unselect();
                section.select();

                // here comes your intent, to start the new activity.
           }
        });

for your drawerToggle problem:

// use the after init method, not the init method.

    @Override
    public void afterInit(Bundle savedInstanceState) {
        // shows a back button, instead of the drawer icon
        drawer.showActionBarMenuIcon(MaterialNavigationDrawer.ActionBarMenuItem.BACK);
    }

and thank you for your hint with the dummyActivity.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Hi,
Thanks for your quick reply.
afterInit() method does work but Selecting the section doesn't work with the listener for SecondActivity, and I found one more thing that selecting the same section(which launches this activity) again create new Intent. similarly selecting that again same activity is lauched.
And Now if I press back(again & again) I get drawer open with second section selected, till I get to first section fragment.

Also can you please give any example on how can I avoid using first fragment? What will happen if my first section is also an activity?

In your example app, SetCustomFragmentActivity has this.setCustomFragment(); which doesn't loads the instruction fragment please check.

I just simply want to replace my app navigation which has multiple activities (not fragments) with the NavigationDrawer, that's why I wanted the drawer section to have activity instead of fragment(with proper selection) if this can be achieved using your lib? otherwise I have convert everything to fragment.

Please let me know if that is possible and please give update on SectionListener that you suggested me as it doesn't work when Activity is lauched but does work when back is pressed .

Hope you understand what I am asking.
Thanks.

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

I have correct the example. Now the custom fragment loads ;).
See here:
https://github.com/madcyph3r/AdvancedMaterialDrawer/blob/2dd00a02f395ddd33a057c91f7ccd5fd035ee472/example/src/main/java/de/madcyph3r/example/example/functionally/SetCustomFragmentActivity.java

So you can set a custom fragment on every activity load. Your menu must not have an fragment section, but then you should use a custom fragment on start.

And set the onClick listener like this:

        // global var. Save the latest activitySection
        private final MaterialSection tmpSection = null;

        yourSection.setOnClickListener(new MaterialSectionOnClickListener() {
            @Override
            public void onClick(MaterialSection section, View view) {
                if(drawer.getCurrentSection() != null)
                    drawer.getCurrentSection().unselect();

                if(tmpSection == null && tmpSection != section) {
                    tmpSection = section;
                    section.select();

                    // if you use on every activity the same menu, then send the selected section position
                    int pos = drawer.getCurrentMenu().getSectionPosition();

                    // start activity
                    Intent myIntent = new Intent(drawer, B.class);
                    myIntent.putExtra("selPos", pos);
                    drawer.startActivity(myIntent);


                  // on the new activity do this in the after init method and you set the custom fragment:
                  // Intent intent= getIntent();
                  // Bundle b = intent.getExtras();
                  // if(b!=null)
                  // {
                  // int pos =(int) b.get("selPos");
                  // drawer.getCurrentMenu().getSection(pos).select();
                  //}

                }

            }
        });

If you press back button use the no close prev actitivty example. see here:
https://github.com/madcyph3r/AdvancedMaterialDrawer/blob/2dd00a02f395ddd33a057c91f7ccd5fd035ee472/example/src/main/java/de/madcyph3r/example/example/functionally/noClosePrevDrawerActivity/NoCloseActivity.java

Important: this is a really bad practice. Better you use fragments, it's not really difficult. Use only a new Activity, if you don't need the menu or you need a new drawer menu with a different context.
And it's complicated, to send every time the menu position. And it creates every time a new menu, this makes your app slower and you need more ram, because every activity is in your ram, if you don't call finish() on activity start.

Ram Example:
1 Activity and 5 Fragments:
in your ram is 1 activity with the drawer. The drawer creates on activity start, only one time.
Only the fragments will changed.

5 Activities, every has 1 Frament (custom Fragment):
every new activity start creates new own menu. (it's the same menu, but different objects)
so you have 5 activities and 5 menu objects in your ram.

You see, you need more ram and you create on every activity start a new menu. Your app get's slower.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

OK Thanks.

But How to select the correct section after activity loads I was not able to do that with your Listener.
Can you please check that how can I select a section when activity is lauched (and suppose custom fragment is loaded)?

What I want is like Gmail. I have inbox activity which loads email(inbox section is selected) and then clicking individual email opens new activity which has different content but must have the drawer and inbox selected.

How can I achieve this with Activity?Or is it possible to do with activity or Fragment is must here?

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

For this case you use normally fragments. If i have time today, i kan make a small example for you with the activity. But it's easier, if you use fragments.

See here, the wiki from neokree explains, how do you convert your activity to fragment.
https://github.com/neokree/MaterialNavigationDrawer/wiki/Moving-to-MaterialNavigationDrawer

It's very easy.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Yes I actually started to convert them in Fragments(because clicking same section again launches activity as I said above). I was going to implement MasterChild Fragment which neokree has done, but then I got link to this lib I tested it on API8 device it worked so I changed my mind to use this. But I still need master child type navigation with drawer every where. As you have advanced his library I think ,can still use that Masterchild fragment.

Lets see If I am able to make it like Gmail does.

Thanks for your support.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

You can also Include a sample with Masterchild fragment in your example so that it will be helpful for someone working with multilevel navigation.

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

Okay, i will add an master child example. If you can't get it to work, the write here. Then i will make an example this evening. Its a little different from neokree.

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

Here i have made an master child example.

See here: https://github.com/madcyph3r/AdvancedMaterialDrawer/blob/master/example/src/main/java/de/madcyph3r/example/example/functionally/MasterChildNavActivity.java

and here: https://github.com/madcyph3r/AdvancedMaterialDrawer/tree/master/example/src/main/java/de/madcyph3r/example/example/functionally/masterChildNavActivity

have fun with it ;).

from advancedmaterialdrawer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.