Is there a way I can store/retrieve arbitrary values from a view, similar to HTML5 data attributes?
This way, I can have a view call generic onClick() methods and the method can retrieve the related data.
e.g:
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="setCountry"
android:src="@drawable/ic_flag_germany" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="setCountry"
android:src="@drawable/ic_flag_france" />
...
I would like to be able to retrieve a value from the one that got clicked.
public void setCountry(View v){
//retrieve data somehow
}
You can use the
View‘s tag property. It is intented for that purpose.For example:
…