0

I have a listview which i want it for displaying a text and corrs image. I have used an arrayadapter for it. I am able to get an arraylist of hashmaps containing the values of the text and the url for the image.

<Arraylist<Hashmap<String,string>> testdata  :  "name" and "image_url"

Now i am trying to bind it. But no image is shown and the logcat shows resolveuri failed on bad bitmap. ( my url is "/com.example.vocab.MainActivity/res/drawable-hdpi/right_icon.png" ). What am i doing wrong? Thanx in advance for any help.

  // Binding resources Array to ListAdapter
        this.setListAdapter(new SimpleAdapter(Grammar_tab_all.this, testdata ,
                R.layout.list_item, new String[] { "name","img_url"},
                new int[] { R.id.module_name_item, R.id.img_recom}));
        final ListView lv = getListView();
Abhinav
  • 722
  • 2
  • 11
  • 27
  • A String is not an image, so you can't hope to resolve such a thing from it. Also this is not enough code. – JoxTraex Aug 29 '12 at 08:25

5 Answers5

0

Instead of this <Arraylist<Hashmap<String,string>> testdata try with this <Arraylist<Hashmap<String,Object>> testdata if you need more refer this link http://developerboards.att.lithium.com/t5/AT-T-Developer-Program-Blogs/Developing-Apps-for-Android-Beyond-quot-Hello-World-quot-Part-I/ba-p/28983/page/2

Aerrow
  • 12,086
  • 10
  • 56
  • 90
0

To show the drawable images in listview, best method is to store only the int id of drawable image.

Try this.

listItems = new ArrayList<HashMap<String,Integer>>();
String fieldName = "image_id";

HashMap<String, Integer> listData1 = new HashMap<String, Integer>();
HashMap<String, Integer> listData2 = new HashMap<String, Integer>();

listData1.put(fieldName, R.drawable.camera_icon_focus_dim);
listData2.put(fieldName, R.drawable.camera_icon_scene_mode);

listItems.add(listData1);
listItems.add(listData2);

SimpleAdapter listItemAdapter = new SimpleAdapter(
    this,
    listItems,
    R.layout.image_list_item,
    new String[] { fieldName },
    new int[] { R.id.listitem_img });
Chirag
  • 56,621
  • 29
  • 151
  • 198
0

You have to use a custom list view : check out this website http://blog.sptechnolab.com/2011/02/01/android/android-custom-listview-items-and-adapters/

Malek Hijazi
  • 4,112
  • 1
  • 26
  • 31
0

If you use images from android resources folder then you can use the

// get Drawable from resources folder
Resources res = context.getResources();
Drawable drawable = res.getDrawable( R.drawable.myImage );

ImageView mImageView.setImageDrawable( mDrawable );
// or
ImageView mImageView.setImageBitmap( mBitmap );

The ImageView is the one from your ListItems layout. I wrote for every ListView a own ListAdapter in which i inflate the special layout and set the data to the layout.

Happo
  • 1,375
  • 3
  • 16
  • 34
0

You need a custom listadapter if you want to have different images and this one is the best tutorial I have ever found on internet about this topic :)

Dusean Singh
  • 1,456
  • 2
  • 15
  • 20