请原谅我,我是新手:新手。我使用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