Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
200 views
Welcome To Ask or Share your Answers For Others

1 Answer

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(AdapterView<?> parent, View view, int position, long id){
        //Do stuff
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...