Git Product home page Git Product logo

Comments (10)

JakeWharton avatar JakeWharton commented on July 23, 2024

@SimonVT and I talked about this offline earlier this week and are going to implement and API and sample for the next version.

from android-menudrawer.

kaciula avatar kaciula commented on July 23, 2024

Nice. Do you have an estimate on when the next version will be available?

Thanks for all your hard work!

from android-menudrawer.

JakeWharton avatar JakeWharton commented on July 23, 2024

I'm hoping to have it implemented in the next week. As for an actual release, well that's up to @SimonVT.

from android-menudrawer.

JakeWharton avatar JakeWharton commented on July 23, 2024

Also, fragments are just management containers around views, the thing with which this library operates. You can easily use it with fragments as it stands now. The problem is that there are no convenience APIs which there should be.

from android-menudrawer.

kaciula avatar kaciula commented on July 23, 2024

I discovered it's quite easy to use fragments with the library. I thought it would be more tricky but I was wrong. The library works flawlessly. Thanks.

from android-menudrawer.

swanhtet1992 avatar swanhtet1992 commented on July 23, 2024

@SimonVT , @JakeWharton
Hi guys,
any plan to add sample for working with Fragments?
I still can't figure out how to get this done. Thanks.

from android-menudrawer.

SimonVT avatar SimonVT commented on July 23, 2024

What's the issue? There's no difference in how you add a Fragment to the menu compared to the content. Define it in xml, or add it from code. When adding from code, either supply your own menu layout with a known container id, or use MenuDrawer#getMenuContainer() to get the base menu viewgroup.

from android-menudrawer.

swanhtet1992 avatar swanhtet1992 commented on July 23, 2024

@SimonVT,

Here is the complete question!

I'm trying to attach the MenuDrawer to the Fragment. But there is an error which said "no view found". I think I'm wrong with the layout files but can't really figure it out yet.

Here is the Log:

03-02 12:53:26.950: E/AndroidRuntime(6780): FATAL EXCEPTION: main
03-02 12:53:26.950: E/AndroidRuntime(6780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragmentmenu/com.example.fragmentmenu.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f050006 (com.example.fragmentmenu:id/fragment_container) for fragment ContentFragment{422dcf80 #0 id=0x7f050006}
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.os.Looper.loop(Looper.java:137)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.ActivityThread.main(ActivityThread.java:4898)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at java.lang.reflect.Method.invoke(Method.java:511)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at dalvik.system.NativeStart.main(Native Method)
03-02 12:53:26.950: E/AndroidRuntime(6780): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f050006 (com.example.fragmentmenu:id/fragment_container) for fragment ContentFragment{422dcf80 #0 id=0x7f050006}
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.Activity.performStart(Activity.java:5216)
03-02 12:53:26.950: E/AndroidRuntime(6780):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
03-02 12:53:26.950: E/AndroidRuntime(6780):     ... 11 more

Here is my codes:

MainActivity which extends FragmentActivity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (findViewById(R.id.fragment_container) != null) {
            if (savedInstanceState != null)
                return;

            ContentFragment  content = new ContentFragment();
            getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, content).commit();

            // The AboveFragment is working if I didn't attach MenuDrawer.
            // When I attach MenuDrawer like below, it said no view found for "fragment_container"

            mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT);
            MenuListFragment mMenu = new MenuListFragment();
            getSupportFragmentManager().beginTransaction().add(R.id.menu_frame, mMenu).commit();
            mMenuDrawer.setMenuView(R.layout.menu_frame);

            // on the other hand, MenuDrawer attachment is working if I didn't attach the ContentFragment.
        }
    }

MenuListFragment which extends ListFragment

    // the code for MenuAdapter is the same as sample app.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.list, null);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        List<Object> menuItems = new ArrayList<Object>();
        menuItems.add(new Category("Courses"));
        menuItems.add(new Item("Course 1", R.drawable.ic_action_select_all_dark));
        menuItems.add(new Item("Course 2", R.drawable.ic_action_select_all_dark));
        menuItems.add(new Item("Course 3", R.drawable.ic_action_select_all_dark));
        menuItems.add(new Category("Resource"));
        menuItems.add(new Item("Guitar Tuner", R.drawable.ic_action_select_all_dark));

        mAdapter = new MenuAdapter(menuItems);
        setListAdapter(mAdapter);
    }

ContentFragment which extends Fragment

    public ContentFragment() { 
        this(R.color.red);
    }

  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (savedInstanceState != null)
            mColorRes = savedInstanceState.getInt("mColorRes");
        int color = getResources().getColor(mColorRes);

        FrameLayout v = new FrameLayout(getActivity());
        v.setBackgroundColor(color);
        return v;
    }

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

menu_frame.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/menu_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

from android-menudrawer.

SimonVT avatar SimonVT commented on July 23, 2024

Don't use Activity#setContentView, use MenuDrawer#setContentView and MenuDrawer#setMenuView.

from android-menudrawer.

swanhtet1992 avatar swanhtet1992 commented on July 23, 2024

oh. Thanks man. I got it! :)

from android-menudrawer.

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.