如何在 HashMap 中设置图片 URI
How to set image URI in HashMap
我正在构建一个列表视图,我得到了我想要使用 map.put 的 HashMap 的图像的 URI。
获取 URI 的函数工作正常我可以使用 setImageURI(uri) 设置图像视图。
我应该在 map.put("flag", value);
中使用什么值
以下代码是postexecute的一部分
try {
android = json.getJSONArray(TAG_OS);
oslist.clear();
for(int i = 0; i < android.length(); i++){
JSONObject c = android.getJSONObject(i);
String counter = c.getString(TAG_COUNTER);
String id = c.getString(TAG_ID);
String phono = c.getString(TAG_PHONO);
String error = c.getString(TAG_ERROR);
cur.moveToFirst();
cur.moveToPosition(i);
name = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
Uri uri = getPhotoUri(Long.parseLong(fetchContactIdFromPhoneNumber(phono)));
HashMap<String, String> map = new HashMap<String, String>();
map.put("flag", value);
map.put(TAG_COUNTER, name);
map.put(TAG_ID, id);
map.put(TAG_PHONO, phono);
map.put(TAG_ERROR, error);
oslist.add(map);
list=(ListView)findViewById(R.id.lv_addcontact);
ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
R.layout.list_item,
new String[] {"flag",TAG_COUNTER, TAG_PHONO, TAG_ERROR}, new int[] {
R.id.flag,R.id.txtView_name, R.id.txtview_number, R.id.txtview_check});
list.setAdapter(adapter);
}
}
感谢大家的帮助
您绝对必须在字符串到字符串的映射中包含 Uri 吗?如果是这样,您可以使用 uri.toString()
获取 Uri 的字符串表示形式,然后通过执行 Uri.parse(string)
.
从地图中检索 Uri
否则我会创建一个 HashMap<String, Parcelable>
我正在构建一个列表视图,我得到了我想要使用 map.put 的 HashMap 的图像的 URI。
获取 URI 的函数工作正常我可以使用 setImageURI(uri) 设置图像视图。
我应该在 map.put("flag", value);
中使用什么值以下代码是postexecute的一部分
try {
android = json.getJSONArray(TAG_OS);
oslist.clear();
for(int i = 0; i < android.length(); i++){
JSONObject c = android.getJSONObject(i);
String counter = c.getString(TAG_COUNTER);
String id = c.getString(TAG_ID);
String phono = c.getString(TAG_PHONO);
String error = c.getString(TAG_ERROR);
cur.moveToFirst();
cur.moveToPosition(i);
name = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
Uri uri = getPhotoUri(Long.parseLong(fetchContactIdFromPhoneNumber(phono)));
HashMap<String, String> map = new HashMap<String, String>();
map.put("flag", value);
map.put(TAG_COUNTER, name);
map.put(TAG_ID, id);
map.put(TAG_PHONO, phono);
map.put(TAG_ERROR, error);
oslist.add(map);
list=(ListView)findViewById(R.id.lv_addcontact);
ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
R.layout.list_item,
new String[] {"flag",TAG_COUNTER, TAG_PHONO, TAG_ERROR}, new int[] {
R.id.flag,R.id.txtView_name, R.id.txtview_number, R.id.txtview_check});
list.setAdapter(adapter);
}
}
感谢大家的帮助
您绝对必须在字符串到字符串的映射中包含 Uri 吗?如果是这样,您可以使用 uri.toString()
获取 Uri 的字符串表示形式,然后通过执行 Uri.parse(string)
.
否则我会创建一个 HashMap<String, Parcelable>