我有以下代碼,我試圖通過使用this類創建一個分離列表。獲取Android中的HashMap元素的值時遇到問題
我有這樣的:
public Map<String, ?> createItem(String title, String caption, String uri) {
Map<String, String> item = new HashMap<String, String>();
item.put(ITEM_TITLE, title);
item.put(ITEM_CAPTION, caption);
item.put(ITEM_URI, uri);
return item;
}
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
/** @todo Draw the splash screen */
setContentView(R.layout.list_complex);
List<Map<String,?>> security = new LinkedList<Map<String,?>>();
security.add(createItem("Remember passwords", "Save usernames and passwords for Web sites","uri"));
security.add(createItem("Clear passwords", "Save usernames and passwords for Web sites","uri2"));
security.add(createItem("Show security warnings", "Show warning if there is a problem with a site's security","uri3"));
SeparatedListAdapter adapter = new SeparatedListAdapter(this);
adapter.addSection("Security", new SimpleAdapter(this, security, R.layout.list_complex,
new String[] { ITEM_TITLE, ITEM_CAPTION}, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
ListView list = new ListView(this);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
try{
Log.v(TAG, "Pressed id: "+(parent.getItemAtPosition(position).getClass()));
}catch(Exception e){
Log.v(TAG, "Field not found: "+e.getCause()+" : "+e.getMessage());
}
//Log.v(TAG, "Pressed id: "+parent.);
// Intent newActivity = new Intent(view.getContext(),agones.class);
// startActivity(newActivity);
}
});
list.setAdapter(adapter);
this.setContentView(list);
我想在這裏做的是讓從HashMap中的場URI。如果我登錄了這一點,它告訴我,這個類是實例的HashMap的,但是當我嘗試使用方法.get()
上,Eclipse中這樣說:
The method get() is undefined for the type Class<capture#5-of ? extends Object>
如何去修復呢?如果這很簡單,我很抱歉,但是因爲我是新人,所以我無法把頭繞在這裏。
仍返回'的get()方法是未定義的類型類<捕獲#2的?擴展對象>'但現在用一個捕獲#2 –
@Janis Peisenieks檢查我更新的帖子。 –
你知道,他們兩個完全一樣嗎? –