請原諒我,我是新手:新手。我使用simple_list_item_2
來顯示11個項目。這11個項目已使用HashMap
,然後SimpleAdapter
加載。這在顯示所有內容時工作正常。問題是我無法獲得setOnItemClickListener
。該代碼:使用simple_list_item_2並無法弄清楚如何使用setOnItemClickListener
public class TwoLineActivity extends ListActivity
{
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(2);
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.scrolllist);
// enter valid data, these 2 are the same as the remaining 9
HashMap<String, String> maplist;
maplist = new HashMap<String, String>();
maplist.put("line1", "a11 data");
maplist.put("line2", "asd asd ad 1234569780");
list.add(maplist);
maplist = new HashMap<String, String>();
maplist.put("line1", "a12 data");
maplist.put("line2", "asd asd ad 1234569781");
list.add(maplist);
String[] from = { "line1", "line2" };
int[] to = { android.R.id.text1, android.R.id.text2 };
SimpleAdapter adapter = new SimpleAdapter(this, list, android.R.layout.simple_list_item_2, from, to);
setListAdapter(adapter);`
因此,直到這裏事情是偉大的,我得到我的名單。現在,我希望能夠從列表中選擇一個項目,所以我編寫了未來2線
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener()
{ .....
我收到以下錯誤
The method setAdapter(SimpleAdapter) is undefined for the type ArrayList<HashMap<String,String>>
和
The method setOnItemClickListener(new AdapterView.OnItemClickListener(){}) is undefined for the type ArrayList<HashMap<String,String>>
*「沒有錯誤。」* - 您會得到什麼特定錯誤?你的應用崩潰了嗎?在這種情況下,請發佈堆棧跟蹤。謝謝! – 2012-03-10 15:46:04
您的活動是否擴展ListActivity或活動? – 2012-03-10 19:17:05