Issue
I am implementing a navigation Drawer as per: http://developer.android.com/training/implementing-navigation/nav-drawer.html
The tutorial only shows a single TextView with ID android:id="@android:id/text1" and this is populated for the ListView using:
mDrawerList.setAdapter(new ArrayAdapter<String>(
this,
R.layout.drawer_list_item,
mDrawerItems));
Now, I want to include an ImageView inside each ListView item. This will represent the Icon for each item.
Question: Inside my xml for the list items (where the TextView text1 is located), I have included an ImageView.
What do I need to name the ID for the ImageView?
And then, do I simply add the drawable-array reference to the setAdapter like this?
mDrawerList.setAdapter(new ArrayAdapter<String>( this, R.layout.drawer_list_item, mDrawerItems, mDrawerIcons));
Thank you
Solution
I found out that creating an ArrayAdapter
in the format above does not allow you to input more than one set of data to the Adapter
. For instance, I can only use my list of Drawer Navigation names contained in the Array<String>
: mDrawerItems. To pass Icons and other data to the adapter, I have two option:
Simple Adapter
used with aMap
, orCustom Adapter.
Examples of both can be found here: http://www.vogella.com/articles/AndroidListView/article.html, and here:
http://www.shenhengbin.wordpress.com/2012/03/17/listview-simpleadapter/
Answered By - KickAss
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.