安卓:onListItemClick的活动onListItemClick

2023-09-03 22:31:19 作者:露娜味道很好

previous一次我问一个问题,我在这里学到了很多东西,所以我想这是值得一试再试一次吧。

我现在用的是懒惰的名单由费多尔从这个链​​接: How我做的ListView图像的延迟加载?

它的工作就像一个魅力。但费多尔正在他的主要类扩展活动,而不是 ListActivity 的。正因为如此,我不再能够使用listItemClick监听器。 Eclipse的声明身边 onListItemClick一些错误()。它的工作原理当我打开

  @覆盖
保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
    super.onListItemClick(L,V,位置ID);
     这里//意图发射
}
 

 保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
     这里//意图发射
   }
 

但意图发射器不工作。无论是做了Toast通知。

安卓开发onListItemClick的使用

当我打开活动 ListActivity ,Eclipse不错开,但我的模拟器给了我强制关闭。

如何获得

onListItemClick()点击活动(preferable) 或者我变换code到 ListActivity 没有强制关闭?

感谢很多提前。

解决方案

一个listItemClickListener连接到的ListView 。当您更改 ListActivity 活动,你的该类已不再具有与其关联的视图,因此一个活动类有不知道该怎么做一个onListItemClickListener。

您只需要连接一个监听到你的的ListView

 
listview.setOnItemClickListener(新onItemClickListener(){
    @覆盖
    保护无效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: How do I do a 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.

解决方案

A listItemClickListener is attached to a ListView. When you changed ListActivity to Activity, your class no longer has a view associated with it and thus an Activity class has no idea what to do with an onListItemClickListener.

You just have to attached a listener to your ListView:


listview.setOnItemClickListener(new onItemClickListener(){
    @Override
    protected void onListItemClick(){
        //Do stuff
    }
});

相关推荐