views:

362

answers:

1

I am creating lists in my android app and would like to capture the text of the list item that is clicked but I want to do it in a seperate function so I only have to write the code once. And I want to be able to compare the string to another sting.

What is the best way to do this?

+1  A: 

You need OnItemClickListener() set to your list and overwrite

onItemClick(AdapterView<?> parent, View view, int position, long id)

then get you text either from item itself or from the view.

Alex Volovoy
Thanks, I got that to work but, I cant compare it for some reason. It makes me use CharSequence as a type instead of String and when I compare it to another string it does not work. Any ideas?
dweebsonduty
There is bunch of methods on the String object to compare it with CharSequence. and there is toString on cs as well. How you're getting value ( code ) ?
Alex Volovoy
Ok I figured it out, actually SE figured it out for me. I was using == to compare. I am such a newb at this.... http://stackoverflow.com/questions/2704956/strings-dont-seem-to-be-equal-in-java-on-android-even-though-they-print-the-sam
dweebsonduty