0

我有一个列表视图,我希望它用于显示文本和 corrs 图像。我已经为此使用了arrayadapter。我能够获得一个包含文本值和图像 url 的哈希图数组列表。

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

现在我正在尝试绑定它。但是没有显示图像,并且 logcat 显示 resolveuri 在错误的位图上失败。(我的网址是“/com.example.vocab.MainActivity/res/drawable-hdpi/right_icon.png”)。我究竟做错了什么?提前感谢您的帮助。

  // 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();
4

5 回答 5

0

您必须使用自定义列表视图:查看此网站 http://blog.sptechnolab.com/2011/02/01/android/android-custom-listview-items-and-adapters/

于 2012-08-29T08:30:04.490 回答
0

如果你想拥有不同的图像,你需要一个自定义的列表适配器,这是我在互联网上找到的关于这个主题的最好的教程:)

于 2012-08-29T09:12:48.020 回答
0

如果您需要更多信息,请不要<Arraylist<Hashmap<String,string>> testdata尝试此链接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<Arraylist<Hashmap<String,Object>> testdata

于 2012-08-29T08:27:47.633 回答
0

要在列表视图中显示可绘制图像,最好的方法是仅存储可绘制图像的 int id。

尝试这个。

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 });
于 2012-08-29T08:28:21.897 回答
0

如果您使用 android 资源文件夹中的图像,那么您可以使用

// 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 );

ImageView 是您的 ListItems 布局中的一个。我为每个 ListView 编写了一个自己的 ListAdapter,我在其中扩展了特殊布局并将数据设置为布局。

于 2012-08-29T08:39:23.610 回答