[英]How to set image URI in HashMap
我正在建立一個列表視圖,並使用map.put獲取到HashMap的圖像的URI。
我可以使用setImageURI(uri)設置圖像視圖,以獲取URI的功能工作正常。
我應該在map.put(“ flag”,value);中使用什么值;
以下代碼是后執行的一部分
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的String表示形式,然后通過執行Uri.parse(string)
從地圖中檢索Uri。
否則,我只是創建一個HashMap<String, Parcelable>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.