1

Can I set an ArrayAdapter < Object > or ArrayAdapter < String > with multiple objects? I have a ListView Item with an Icon and a TextView. I can use this to set the TextView names:

    mDrawerList.setAdapter(new ArrayAdapter<String>(
            this,
            R.layout.drawer_list_item,
            mDrawerItems));

But I also want to assign an Icon to each ImageView for each ListView Item. I have got an int[] with all Drawable Icon References, how can I pass this to the Adapter?

The ImageView ID is: android:id="@android:id/icon1"

The TextView ID is: android:id="@android:id/text1"

KickAss
  • 4,210
  • 8
  • 33
  • 41
  • 2
    What you need is a custom adapter. You can subclass `BaseAdapter` for that. Tutorial: [Android: Custom ListView with Image and Text using BaseAdapter](http://theopentutorials.com/tutorials/android/listview/android-custom-listview-with-image-and-text-using-baseadapter/). – Vikram Aug 30 '13 at 22:14
  • I was hoping to avoid a custom adapter, trying to take shortcuts :P Thank you I will do that now. Post an official answer and I'll accept it :) thanks! – KickAss Aug 30 '13 at 22:17
  • You'll see that once you follow the tutorial I suggested, you'll be writing custom adapters on the fly. There's nothing to them really. It'll make your life easier. About posting an answer: What I gave you was a suggestion, not an answer. You can `upvote` the comment to indicate that it helped you. – Vikram Aug 30 '13 at 22:21
  • Thanks buddy. I can't upvote until 15 reputation. I'm a newbie lol But yeah, I'll learn to code custom adapters. Definitely the more strategic option :) – KickAss Aug 30 '13 at 22:23

1 Answers1

0

You can use SimpleAdapter with Map for data. More:http://developer.android.com/reference/android/widget/SimpleAdapter.html

KickAss
  • 4,210
  • 8
  • 33
  • 41
getKonstantin
  • 1,220
  • 9
  • 14