0

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?

shaneburgess
  • 15,702
  • 15
  • 47
  • 66

1 Answers1

1

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
  • 67,778
  • 13
  • 73
  • 54
  • 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? – shaneburgess May 24 '10 at 21:34
  • 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 May 24 '10 at 21:38
  • 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 – shaneburgess May 24 '10 at 22:05