Comments (10)
@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.
Nice. Do you have an estimate on when the next version will be available?
Thanks for all your hard work!
from android-menudrawer.
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.
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.
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.
@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.
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.
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.
Don't use Activity#setContentView, use MenuDrawer#setContentView and MenuDrawer#setMenuView.
from android-menudrawer.
oh. Thanks man. I got it! :)
from android-menudrawer.
Related Issues (20)
- Left menu over the action bar HOT 1
- menudrawer with Toolbar HOT 1
- the right side overlaydrawer could not drag freely as left side.
- Menu drawer toggle events HOT 1
- I wonder how can I do menudrawer to not be animated at activity starting time.
- why it's deprecated? HOT 5
- Can't use library using gradle HOT 1
- StackOverflow Issue
- FloatMath has been removed in API 23 HOT 2
- Can I draw the menu with a button click HOT 1
- issue on drawer item click
- drawer item one is to show and another hide
- Noclass definition found
- Use menudrawer across multiple activities
- how to disable open by dragging the edge?
- some think bug on aapt2 HOT 1
- java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1c HOT 7
- How to remove MenuDrawer from my rootView
- Menudrawer left menu Crash just in android API 16 & 17
- Crashed!!! java.lang.UnsupportedOperationException: Can't convert value at index 2 to dimension: type=0x3
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 android-menudrawer.