Reputation: 461
Hi guys this is rather a silly question because i'm confused. what i'm trying to do is to call a method(share to facebook) from an activity inside my adapter.
this is the illustration:
Activity: postToFacebook(Pets dog); listview that holds list of dogs.
Adapter: adapter in which i use to create custom view for better looking.
problem is that i want to set an onLongClickListener on the LinearLayout that holds all the dog's info (this way user can hold any part of the info) to be shared to facebook.
is there a way to do this?
thanks a lot!
Upvotes: 0
Views: 1382
Reputation: 978
If I understand your question you are complety on bad way
In your activity you have an ArrayList (or List) with Dogs information
Something like
ArrayList<Pets> listDogs;
now, you should do this (myListView is your ListView obj)
myListView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
postToFacebook(listDogs.get(pos));
return true;
}
});
In this way you get the position of element selected and call your method from activity and not from adapter.
listDogs.get(pos)
this line return the element of the row selected.
Upvotes: 2