我正在开发一个 Android 应用程序。在我的应用程序中,我必须使用适配器。所以我使用了简单的适配器。
int[] flags = new int[]{
R.drawable.img1,
R.drawable.img2,
};
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<number.size();i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("txt", number.get(i));
hm.put("flag", Integer.toString(flags[i]) );
aList.add(hm);
}
String[] from = { "flag","txt"};
// Ids of views in listview_layout
int[] send = { R.id.flag,R.id.txt};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.autocomplete_layout, from, send);
现在我想使用我自己的可绘制数组列表而不是从资源中绘制。
Drawable d="some downloaded image from server"
现在我想在hashmap中使用上面的d。
hm.put("flag", d.toString() );
上面的 stamenet 不起作用。我知道它是因为我之前发送了图像 ID。现在我正在将图像转换为字符串。
所以我必须把我的图像放到 hashmap hm 中。但是,如果我使用我下载的可绘制图像,我该如何放置?