0

我也在使用 Sharkey 的 SepatedListAdapter,并且从基础版中对其进行了相当多的定制。我添加了更多文本字段和图像视图,数据从数据库中提取出来。我无法理解的一件事是如何在适配器中更新 imageview 的 src。

例如,这就是我所拥有的(包括对 Sharkey 代码的更改):

我是我的布局,我有一个 imageview:

    <ImageView
        android:id="@+id/list_complex_image" 
        android:layout_width="30dp"
        android:layout_height="30dp" />

在我的main.java中:

public Map<String,?> createItem(String title, String caption, String flightno, String extra, String imagesrc) {  
    Map<String,String> item = new HashMap<String,String>();  
    item.put(ITEM_TITLE, title);  
    item.put(ITEM_CAPTION, caption);
    item.put(ITEM_FLIGHTNO, flightno);
    item.put(ITEM_EXTRA, extra);
    item.put(ITEM_IMAGESRC, imagesrc);

    return item;  
} 

进一步下来,我有:

        adapter.addSection(sEventDate + sExtraInfo, new SimpleAdapter(this, currentListSection, R.layout.list_complex,   
                    new String[] { ITEM_TITLE, ITEM_CAPTION, ITEM_FLIGHTNO, ITEM_EXTRA, ITEM_IMAGESRC }, 
                    new int[] { R.id.list_complex_title, R.id.list_complex_caption, R.id.list_complex_flightno, R.id.list_complex_extra, R.id.list_complex_image }));  

粗略地说,我认为它试图为图像视图设置一个文本值,它不需要文本值。我想编辑src字段

在 Sharkey 的 separatorlistadapter.java 中他有:

public void addSection(String section, Adapter adapter) {  
    this.headers.add(section);  
    this.sections.put(section, adapter);  
}  

在将项目添加到适配器之前,我有什么想法可以更新它以包括对 ImageView 的src更改?

非常感谢,J

4

1 回答 1

0

我已经找到了答案,供其他人搜索。

感谢 David Cesarino 的以下帖子: 在此处发布

原来我可以引用 Resource Drawable 对象的 String.ValueOf() 参数。因此,我可以将字段值设置为:而不是使用纯字符串(如文本字段):

String.valueOf(R.drawable.my_shape_image)

发挥魅力,干杯!Ĵ

于 2013-02-26T14:57:04.227 回答