我在地圖上一個HashMap得到HashMap中的值,並添加列表視圖
HashMap<String, Integer> map = new HashMap<String, Integer>();
有一定的價值。我想逐個獲取值並將其添加到列表視圖中。這是在圖中的值是
{意圖{CMP =藍牙/ 300} = 300,意圖{CMP =音頻/ 400} = 400, 意圖{CMP =視頻/ 500} = 500,意圖{ cmp = Display/100} = 100,Intent { cmp = WiFi/200} = 200}
在listview中有兩個textview。 我想在列表視圖中顯示爲
顯示100
無線網絡200
藍牙現在300
我公開我的適配器類別,這將是對你有所幫助。 ...
private class NewAdapter extends BaseAdapter {
public NewAdapter(IntentTestingActivity intentTestingActivity,
HashMap<String, Integer> map) {
}
@Override
public int getCount() {
Log.d(TAG, "Map size is: " + map.size());
return map.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
View v = view;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.class_name, null);
}
TextView className = (TextView) v.findViewById(R.id.name);
TextView tagName = (TextView) v.findViewById(R.id.tag_name);
Integer key_name;
key_name = map.get(name);
Log.d(TAG, "Complete map is: " + map.toString());
// String tag = map.get(tagName).toString();
// Integer name = map.get(className);
String keyName;
keyName = map.toString();
Log.d(TAG, "KeyName is: " + map.get(tag));
for (int i = 0; i < map.size(); ++i)
Log.d(TAG, "Tag is: " + tag + " and Name is: " + name + " and Intent is: "+intent);
HashMap<String, Integer> hashmap = map;
for (Entry<String, Integer> e : hashmap.entrySet()) {
String key = e.getKey();
int value = e.getValue();
Set<String>keyname = map.keySet();
Log.d(TAG, "Key: " + key+ " Value: "+value);
}
className.setText(name.toString());
// tagName.setText(keyName);
return v;
}
}
where nam e是一個String,其中包含所有keyValue,如Display,Vedio等。
Thanx提前...
我不明白所有這些+1和收藏夾?我錯過了什麼:$? – 2012-02-03 09:09:53