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 have been working on this all day and after making my own
ArrayAdapter
I couldn't figure out how to change classes in my list.Here's how I found out how to do it. After I called my array i simply finished out my code in that method by doing.
Then after all my text i put
Between I managed to completely customize my
ListView
with custom font and backgrounds. I'm sure a ton of you don't really care. But I'm exited and was hoping by posting this that I might help someone in the future.I have simply added following in
onCreate()
:Outside of
onCreate()
addedsetPaymentDetails()
:Assume you have datasource Fruit contain few strings. You can define the
onCreate()
as following:And then write the
onListItemClick()
as following:I hope it works for you :)
If you are using
ListActivity
then you want to do something like this:This is not the only way to set an
OnItemClickListener
. Look other answers. This is the way I like to do it since it's clearer and easier to read.FE.java
A listItemClickListener is attached to a
ListView
. When you changedListActivity
toActivity
, your class no longer has a view associated with it and thus anActivity
class has no idea what to do with an onListItemClickListener.You just have to attached a listener to your
ListView
: