How To Acces Variable In Arrayadapter Getview From Onitemclick
I have an ArrayAdapter whose getView sets the items in the listview with data. When i click a row in the listview i'd like to start another activity, (which i can do), but send tha
Solution 1:
By Using setTag()
and getTag()
methods you can get data from the adapter in onItemClick()
. like this
in adapter class
@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
rowView.setTag(yourdata_object);
return rowView;
}
in on item click
@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
YourDataObjectitem= (YourDataObject ) view.getTag();
Intenti=newIntent(GetRota.this, someOtherActivity.class);
i.putsomedata;
startActivity(i);
}
Solution 2:
Try this.
You will get position of clicked item in the onItemClick method and a view which is clicked in list. So you can set the tag to view in getView and in onitemClick you can get that view tag and pass to intent.
rowView.setTag(YOURDATA); // in getView@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position,
long id) {
Log.e(TAG, "inside onItemClick");
Intenti=newIntent(GetRota.this, someOtherActivity.class);
(yourData) = view.getTag(); // get the tag value and set to putextra
i.putsomedata;
startActivity(i);
}
Post a Comment for "How To Acces Variable In Arrayadapter Getview From Onitemclick"