请原谅我,我是新人:这方面的新手。我使用 asimple_list_item_2
来显示 11 个项目。这 11 个项目是使用HashMap
then加载的SimpleAdapter
。这在显示所有内容时效果很好。问题是我不能继续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>>