Nullpointer with navigation drawer. Not detecting value assignments - android

I'm trying to create a navigation drawer, but I keep getting a NullPointer error. When I debugged it, the ListView and DrawerLayout values were null, even though I assign them their respective values. Can anyone tell me what's wrong?
public class MainActivity extends ListActivity {
private ArrayList<String> mTitles = new ArrayList<String>();
private ArrayList<String> mUrls = new ArrayList<String>();
private ArrayList<String> mAbstract = new ArrayList<String>();
public ArrayList<String> mDrawerTitles = new ArrayList<String>();
public DrawerLayout mDrawerLayout;
public ListView mDrawerList;
ProgressDialog progressDialog;
public final String TOPSTORYKEY = "878029f7fee45ecd61ca3f52ea027186:19:72302140";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
mDrawerTitles.add("Politics");
mDrawerTitles.add("Technology");
mDrawerTitles.add("Sports");
mDrawerTitles.add("Books");
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
//DrawerListAdapter drawerAdapter = new DrawerListAdapter(this, mDrawerTitles);
mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mDrawerTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
//new HttpJSONLoader().execute();
}
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
EDIT: here is my 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">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#android:id/list"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#android:id/empty"
android:text="No results"
android:layout_centerInParent="true"/>
<!-- 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>

EDIT:
Solution was moving DrawerLayout from drawer_layout.xml to activity_main.xml and making layout have only two children, where first is MainActivity UI, and second is navigation drawer.
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No results" />
</RelativeLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
You need to set proper id in your XML for your ListView - android:id="#+id/left_drawer", which is the same as id are you referring in OnCreate, it causes your error.
Anyway, your implementation is wrong. Please read how to do it properly.
Here it is great explained how to do this - link
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/left_drawer"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No results"
android:layout_centerInParent="true"/>

Related

findViewById returns null on list view

So for some unknown reason (I've also searched around, checked if I wasn't typing the wrong ID or calling it before setting the view), the call findViewById returns null when I try to get the list view of a navigation drawer. I'm also currently following this tutorial, on the section "Inicialize the drawer list".
However, once I call the findViewById, I get a null reference, which later causes a null reference exception when I call the setAdapter method.
So here's the code in question:
public class DrawerActivity extends AppCompatActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks, AndroidFragmentApplication.Callbacks {
[Needless stuff here]
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private ListView mDrawerList;
private String[] mListItems;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
mListItems = getResources().getStringArray(R.array.list_values);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.drawer_list); //this returns null
//null pointer exception happens next
mDrawerList.setAdapter(
new ArrayAdapter<>(
this, R.layout.drawer_list_item, mListItems
)
);
[More following, but it isn't needed]
And here goes the drawer_activity.xml:
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<LinearLayout 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_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<!-- placed here as explained #
http://developer.android.com/training/appbar/setting-up.html-->
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:theme="#style/AppTheme.AppBarOverlay"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="pt.bluecover.wearable3d.DrawerActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!--
This here is the spin bar indicating that the program is loading something
-->
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dip"
android:layout_marginRight="100dip"
android:maxHeight="35dip"
android:minHeight="35dip"
android:minWidth="7dip"
android:maxWidth="7dip"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
android:indeterminate="true" />
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment
android:id="#+id/navigation_drawer"
android:name="pt.bluecover.wearable3d.NavigationDrawerFragment"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="#layout/drawer_drawer" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
And the drawer_drawer.xml:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="#style/AppTheme.NavigationDrawer"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_list"
android:layout_gravity="start"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
tools:context="pt.bluecover.wearable3d.NavigationDrawerFragment" />
So, what may be causing said method to return null?
Following line and all listview realted code must be in NavigationDrawerFragment not in Activity
mDrawerList = (ListView) findViewById(R.id.drawer_list);

Listview on click event not working

i am trying to add on click listener in a listview but when clicked, no action. can you help me find what i did wrong?
This is adapted from one of the example in android tutorial
public class Main extends Activity {
private ListView menuListView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Inflate the menu items for use in the action bar
//getMenuInflater().inflate(R.menu.menu_main,menu);
//Get the Menu List from resources
menu = getResources().getStringArray(R.array.menu);
//get the drawer Layout
menuDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ArrayAdapter<String> itemAdapter = new ArrayAdapter<String>(this,R.layout.custom_menu_list,menu);
//get the list view
menuListView = (ListView) findViewById(R.id.listview);
menuListView.setAdapter(itemAdapter);
menuListView.setOnItemClickListener(new menuItemClickListener());
}
private class menuItemClickListener implements ListView.OnItemClickListener{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("Check","clicked");
}
}
}//
}
This is the xml of the listview textview
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:focusable="false"
android:focusableInTouchMode="false"
/>
This is the 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"
android:background="#FFFFFF">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"/>
<!-- The navigation drawer -->
<ListView android:id="#+id/listview"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/toastMsg"
android:text="Hello"/>
</android.support.v4.widget.DrawerLayout>
Modify you're main.xml file, remove the TextView and run the code. It works
<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"
android:background="#FFFFFF">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"/>
<!-- The navigation drawer -->
<ListView android:id="#+id/listview"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>

How separating Lists with Headers in android?

I am trying that add section separator header for ListView in drawerLayout but i can not see separators and i just see titles.
This my code :
public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public Cursor cursor;
public Cursor cursorsex;
public ArrayList<String> array;
public ArrayList<String> arraysex;
private ArrayAdapter<String> listAdapter ;
private ArrayAdapter<String> listAdaptersex ;
private ListView mDrawerList;
private ListView mDrawerListsex;
.....
Connection to sqlite
.....
sql = db.openDataBase();
cursor = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
array = new ArrayList<String>();
while(cursor.moveToNext()){
Titel_Drawer = cursor.getString(cursor.getColumnIndex("Title"));
array.add(Titel_Drawer);
}
cursor.close();
cursorsex = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
arraysex = new ArrayList<String>();
while(cursorsex.moveToNext()){
Titel_Drawer = cursorsex.getString(cursorsex.getColumnIndex("Comment"));
arraysex.add(Titel_Drawer);
}
cursorsex.close();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerListsex = (ListView) findViewById(R.id.sex);
listAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list,R.id.textView, array);
mDrawerList.setAdapter( listAdapter );
listAdaptersex = new ArrayAdapter<String>(this, R.layout.xxx,R.id.xxx, arraysex);
mDrawerListsex.setAdapter( listAdaptersex );
}
}
This is xxx.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/xxx"/>
This is drawer_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"/>
This is activity_main.xml:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start">
<TextView
android:layout_width="240dp"
android:layout_height="25dp"
android:textSize="20sp"
android:gravity="center"
android:text="#string/prof"
android:background="#drawable/drawer_title_shape" />
<!-- The navigation drawer -->
<ir.makarem.extentions.ClearableEditText
android:id="#+id/SearchEdittxt"
android:drawableLeft="#drawable/ic_action_search"
android:layout_width="240dp"
android:layout_height="35dip"
android:background="#drawable/textlines"
android:gravity="right"
android:hint="#string/action_search" />
<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="#FFDDDDDD"/>
<ListView
android:id="#+id/sex"
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="#FFDDDDDD"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
For example i need to see look like this photo.
I add two TextView for Title and two ListView.
you have to use section header listview to achieve this functionality
Refrence link Section header listview
You need to set a divider for your ListView: (code example)
// white color for example
int[] clr = {0, 0xFFFFFFFF, 0};
listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, clr));
listView.setDividerHeight(1); // set your desired height
Or set the divider in .xml:
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#FFFFFF"
android:dividerHeight="2px" >
</ListView>

Android Navigation Drawer Fail

I'm working on a chat-app and wanted to add a Navigation Drawer like in the GMail-App. I'm new to Java so pls don't kill me :D I tried to add it but it crashes :(
This is some of the code of my Chat.java
public class Chat extends FragmentActivity {
final String[] data ={"Login","Register"};
final String[] fragments ={
"com.linkr.chat.Login",
"com.linkr.chat.Register"};
String username;
BufferedReader reader;
PrintWriter writer;
ArrayList<String> userList = new ArrayList();
public TextView chatTextArea;
TextView inputTextArea;
Button onClickButton;
Boolean isConnected = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setTitle("Linkr");
/*<-- NAVDRAWER -->*/
setContentView(layout.activity_chat);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, data);
final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
final ListView navList = (ListView) findViewById(R.id.drawer);
navList.setAdapter(adapter);
navList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, final int pos,long id){
drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
#Override
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.main, Fragment.instantiate(Chat.this, fragments[pos]));
tx.commit();
}
});
drawer.closeDrawer(navList);
}
});
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.main,Fragment.instantiate(Chat.this, fragments[0]));
tx.commit();
/*<-- NAVDRAWER END -->*/
I also don't get how to use the NavigationDrawer.
This is my activity_chat.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="300dp"
android:layout_height="800dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".Chat"
android:text = "Linkr">
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="300dp"
android:layout_height="800dp"
tools:context=".MainActivity" >
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFF"
android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/inputTextArea"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/onClickButton"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:id="#+id/onClickButton"
android:layout_alignBaseline="#+id/inputTextArea"
android:layout_alignBottom="#+id/inputTextArea"
android:layout_alignParentRight="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/chatTextArea"
android:layout_above="#+id/onClickButton"
android:layout_alignLeft="#+id/inputTextArea"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/onClickButton"/>
Do i need another XML for it? Can someone tell me how this works?
Thank you guys! :)
The android.support.v4.widget.DrawerLayout is designed to be the top ViewGroup and can have two childs. The first one is your Content View (The View which is visible), like the normal Activity layout. The second one is your Drawer View (The View you can pull from the side).
The Content View and the Drawer View can both be a ViewGroup like a RelativeLayout or a single view in your case the ListView.
So your layout should look like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="300dp"
android:layout_height="800dp"
tools:context=".MainActivity" >
<!-- YOUR CONTENT VIEW-->
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="300dp"
android:layout_height="800dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".Chat"
android:text = "Linkr">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/inputTextArea"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/onClickButton"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:id="#+id/onClickButton"
android:layout_alignBaseline="#+id/inputTextArea"
android:layout_alignBottom="#+id/inputTextArea"
android:layout_alignParentRight="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/chatTextArea"
android:layout_above="#+id/onClickButton"
android:layout_alignLeft="#+id/inputTextArea"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/onClickButton"/>
</RelativeLayout>
<--! YOUR DRAWER VIEW -->
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFF"
android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>

The ListView Items in my navigation drawer are there but I can't see the list

The list is there and it goes to whatever activity I send it to but the list the names on the list don't show. I've changed the color of the font and the drawer background and it doesn't show. The item gets highlighted alright and it redirects to the proper activity as it should but there's nothing written in the drawer.
activity_main:
<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">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/menu_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>
drawer_list_item.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="#fff"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
MainActivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listMenu = getResources().getStringArray(R.array.menuArray);
dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
lv1 = (ListView) findViewById(R.id.menu_drawer);
lv1.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, listMenu));
I had set my array like this:
<item name="section" value="Section"/>
when I should have done this:
<item name="section">Section</>

Categories

Resources