Android:onListItemClick in Activity [英] Android: onListItemClick in Activity

查看:127
本文介绍了Android:onListItemClick in Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上一次我在这里问了一个问题,所以我想这是值得一试,再试一次。



我正在使用Fedor的懒惰列表此链接:
懒惰在ListView中加载图像



它的工作方式就像一个魅力。但是,Fedor正在使他的主要类别扩展到 Activity 而不是 ListActivity 。因此,我不再能够使用listItemClick监听器。 Eclipse在 onListItemClick()之间声明一些错误。当我转到

  @Override 
protected void onListItemClick(ListView l,View v,int position,long id ){
super.onListItemClick(l,v,position,id);
// Intent launcher here
}

into

  protected void onListItemClick(ListView l,View v,int position,long id){
// Intent launcher here
}

但意图启动器不起作用。



当我在 ListActivity 中打开活动 code>,Eclipse不会错开,但是我的模拟器给我一个关闭的力量。



如何获取




  • $ {code> onListItemClick()点击活动(最好)

  • 或者我将代码转换为 ListActivity 而不用强制关闭?



非常感谢

解决方案

我正在写我的答案:


1)@Falmarri的代码需要一些更新

2)我建议的修改完全被拒绝XD

3)Stackoverflow不允许我写评论


这是代码:

  ListView listView =(ListView)findViewById(R.id.my_listview_in_layout); 
listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
//做东西
// ...
}
});



参考:根据 android.widget.AdapterView.OnItemClickListener ,公共方法onItemClick()是点击项目时调用方法{而不是未知的保护方法onListItemClick()}


Previous time I asked a question here I learned a lot so I guess it's worth a shot to try it again.

I am using the lazy list by Fedor from this link: Lazy load of images in ListView

It's working like a charm. BUT, Fedor is making his main class extend Activity instead of ListActivity. Because of this, I am no longer able to use a listItemClick listener. Eclipse declares some errors around onListItemClick(). It works when I turn

    @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
     // Intent launcher here
}

into

   protected void onListItemClick(ListView l, View v, int position, long id) {
     // Intent launcher here
   }

But the intent launcher doesn't work. Neither does a toast notification.

When I turn the Activity in a ListActivity, Eclipse doesn't stagger, but my emulator gives me a force close.

How do I get

  • Either onListItemClick() click in the activity (preferable)
  • Or do I transform the code into a ListActivity without force close?

Thanks a lot in advance.

解决方案

I am writing my answer as:

1) the code by @Falmarri needs some update
2) My suggested edit was totally rejected XD
3) Stackoverflow is not allowing me to write a comment.

Here is the code:

ListView listView = (ListView) findViewById(R.id.my_listview_in_layout);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id){
        //Do stuff
        //...
    }
});


Reference: According to android.widget.AdapterView.OnItemClickListener , public method onItemClick() is the method invoked when an item is clicked {instead of unknown protected method onListItemClick() }

这篇关于Android:onListItemClick in Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆