mardi 31 mars 2015

NavigationDrawer, adapter with an image also

i've got a navigationdrawer with this code for filling:



mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
R.layout.item_menu,
R.id.item1,
new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5),
getString(R.string.title_section6),
}));


i need to add an image for each item, not only a string. i already have my item xml (R.layout.item_menu):



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:layout_height="wrap_content">
<ImageView
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/image1"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/item1"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:padding="5dp"
android:layout_toRightOf="@+id/image1"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
</LinearLayout>


but i don't know how to pass the image. any help? thanks


Aucun commentaire:

Enregistrer un commentaire