Error in navigation drawer implementation - android

This is my xml file
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="#+id/listView1"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
when try to run the project it crashed.. the error is
11-05 04:22:16.296: E/AndroidRuntime(1252): FATAL EXCEPTION: main
11-05 04:22:16.296: E/AndroidRuntime(1252): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exaple.customadapter/com.exaple.customadapter.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout
why this error comes? How to solve this.

Related

gmail like Progress bar functionality

I am creating a gmail like progress bar functionality. There seems to be some space between the actionbar and the progress bar.
Following is the code
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="true"
android:layout_width="wrap_content"
android:layout_height="?android:attr/actionBarSize" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
DrawerLayout should contain only two children: FrameLayout for your content and fragment for drawer. Thus ProgressBar should be located inside dynamically created content.
To add a navigation drawer, declare your user interface with a DrawerLayout object as the root view of your layout. Inside the DrawerLayout, add one view that contains the main content for the screen (your primary layout when the drawer is hidden) and another view that contains the contents of the navigation drawer. for more Creating a Navigation Drawer.

My application is crashed after i configure in other pc

When i configure my app in other computer,app is crashed.check my log-cat.I have also added
android-v4-support.jar.
04-26 11:39:54.695: E/AndroidRuntime(4304):
java.lang.RuntimeException: Unable start activity
ComponentInfo{com.rockers.airtasker/com.rockers.airtasker.ProjectHome}:
android.view.InflateException: Binary XML file line #19: Error
inflating class android.support.v4.widget.DrawerLayout
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
Did you add the newest version of it? v4 support libary is famous to cause problems if used in wrong version/dependency.

Android.view.inflateException Binary XML file line #7 Error inflating class<unknown>

This question has been asked previously. Problem is same but the answers couldn't solve my problem.
this question Unknown error while using DrawerLayout? has same problem like me and i tried the steps given but no luck.i have layout file:
activity_main.xml:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- as the main content the following view takes the whole space for content display..using match_parent in both the sections -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<!-- android:layout_gravity="start" tells the Drawerlayout to treat this as the sliding drawer on the left side for the left-to-right
language...and on right side for the right-to-left languages..a solid contrast is used to differentiate it from the content view.. -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:dividerHeight="0dp"
android:background="#ffff"
/>
</android.support.v4.widget.DrawerLayout>
The logcat says android.view.InflateException:Binary XML file line #7:Error inflating class<unknown>..
I have added support library and tried the solution given to that question but i couldnot solve the issue ..

Error strange line between navigation list and fragment DrawerLayout

This strange line appears in my view and don't know the reason
Edit 1: XML
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="320dp"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:background="#color/list_background"/>
</android.support.v4.widget.DrawerLayout>
Go on your XML file, take the DrawerLayout and cut it and put it on the tag before... so you will be able to see how it's designed.
So, put your LinearLayout of the DrawerLayout inside your visible view, edit it, and put it away again.
Sorry all, My Mistake. The shadow was causing this problem
mDrawer.setDrawerShadow(R.drawable.drawer_shadow_rtl, GravityCompat.END);

how to use multiple fragments in the main content view of navigation drawer

I want to show two fragments (one listfragment and other is details fragment) in the main contentview of navigation drawer like below:
But AFAIK, there can be only one view in the main contentview of drawerLayout. So how can achieve this?
Anything you put inside the FrameLayout will be in the main content view.
You can put whatever you want (including multiple Fragments) inside this FrameLayout:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- YOUR CONTENT HERE -->
<!-- Could be layout with multiple views or fragments -->
</FrameLayout
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

Categories

Resources