2

我一直在关注 ListView 的教程,下面的代码给出了错误。我搜索了所有我能找到的论坛,但我不断提出相同的推荐代码。也许所有的论坛都在引用旧版本,也许 Android 已经继续前进了。

无论如何,这是代码和错误消息:

 getListView().setOnItemClickListener(new OnItemClickListener()
 {
 //@Override
 public void onItemClick(AdapterView<?> parent, View view,
 int position, long id) 
 {
 // TODO Sort out error and add function code
 }
 });

错误信息:

 Multiple markers at this line

 -The method setOnItemClickListener(AdapterView.OnItemClickListener in the type
  AdapterView <ListAdapter> is not applicable for the arguments (new   OnItemClickListener(){})

 -OnItemClickListener cannot be resolved to a type

有什么优惠吗?

4

3 回答 3

7

您应该可以通过像这样指定onItemClickListener的父类来解决这个问题:

myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
于 2012-11-28T16:47:14.687 回答
0

尝试这个

ListView listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener()
 {
 //@Override
 public void onItemClick(AdapterView<?> parent, View view,
 int position, long id) 
 {
 // TODO Sort out error and add function code
 }
 });
于 2013-02-27T11:20:58.693 回答
0

我建议这样,如果有ListView,extends ListActivity并处理listitem click inonListItemClick

@Override
    protected void onListItemClick(ListView list, View view, int position, long id) {
        super.onListItemClick(list, view, position, id);
        //handle listitem click.
    }
于 2013-03-14T14:04:54.257 回答