Android : Configuring navigation drawer doesn't show anything but the background

on Monday, August 11, 2014


I'm trying to create a navigation drawer. I followed some tutorials and tweak some of the codes to satisfy my app needs. Now the problem is, the list of items that I want to display is not displaying. Basically I'm just creating an adapter that should be the one holding the content of my list.


Here are the codes:


layout.xml



<?xml version="1.0" encoding="utf-8"?>
<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" >
</FrameLayout>

<!-- The navigation drawer -->
<ListView android:id="@+id/left_slidermenu"
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@drawable/bg_menu"/>

</android.support.v4.widget.DrawerLayout>


strings.xml



<!-- Nav Drawer Menu Items -->
<string-array name="nav_drawer_items">
<item >Dashboard</item>
<item >Flashcard</item>
<item >Qbank</item>
<item >Video Assist</item>
<item >Contact Us</item>
</string-array>

<!-- Nav Drawer List Item Icons -->
<!-- Keep them in order as the titles are in -->
<array name="nav_drawer_icons">
<item>@drawable/ico_dashboard_squared</item>
<item>@drawable/ico_flashback</item>
<item>@drawable/ico_qbank</item>
<item>@drawable/ico_contact_us</item>
<item>@drawable/ico_contact_us</item>
</array>


NavigationDrawListAdapter



public class NavDrawerListAdapter extends BaseAdapter {
private Context context;
private String[] data;
private TypedArray data2;

public NavDrawerListAdapter(Context context, String[] data1, TypedArray data2){
this.context = context;
this.data = data1;
this.data2 = data2;
}

/* (non-Javadoc)
* @see android.widget.Adapter#getCount()
*/
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}

/* (non-Javadoc)
* @see android.widget.Adapter#getItem(int)
*/
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}

/* (non-Javadoc)
* @see android.widget.Adapter#getItemId(int)
*/
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}

/* (non-Javadoc)
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
}

ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);

imgIcon.setImageResource(data2.getInt(position, 0));
txtTitle.setText(data[position]);

return convertView;
}


}


My configuration of the drawer:



mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerListLeft = (ListView) findViewById(R.id.left_slidermenu);

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;

mDrawerListLeft.getLayoutParams().width = width - 150;
mDrawerListLeft.setLayoutParams(mDrawerListLeft.getLayoutParams());

// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

// nav drawer icons from resources
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);

adapter = new NavDrawerListAdapter(getApplicationContext(),
navMenuTitles, navMenuIcons);
mDrawerListLeft.setAdapter(adapter);


Here's a screenshot of the screen


enter image description here


I don't actually know why the list is not there but the background I supplied is there. As you can notice, I don't have an action bar because I don't really need one. Any ideas? Thanks!


0 comments:

Post a Comment