I have a listview that is populated by a by objects from an “Offer” class I’ve written. Obviously, the toString() method is called and that’s the text that’s displayed in each list item. My question is, how do I implement an onItemClickListener that will call one of my getter or setter methods on the particular object whose toString method had been used to populate that item?
For example, I’d like to raise a toast or something when an item is clicked that retrieves a string my getClaimCode() method and displays in the toast (or whatever other dialog or even a new activity).
can I just call the methods by doing something like item.getClaimCode()…?
You don’t have to implement AdapterView.OnItemClickListener, but I do, and in onCreate() I call myListView.setOnItemClickListener(this).
Then for the AdapterView.OnItemClickListener interface, I have the method:
For you, you might do something like:
Of course your Activity doesn’t have to implement the AdapterView.OnItemClickListener and you could create the listener on the fly.