Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set an array as Tag to any View through layout xml in android

Tags:

android

xml

view

I want to bind some extra data with a view. I am using tag in my xml file to add the extra information.

If the data is only String (android:tag="extra Info"), i am able to get the extra data by using getTag() in code.

But i want to bind multiple data as object to a view, for that i am setting an array as tag. When i tried to set android:tag="@array/xyz_array", I am still getting a String object instead of an array from getTag().

Can any body tell me, if i am doing something wrong ??

like image 389
Atmaram Avatar asked Feb 24 '11 04:02

Atmaram


2 Answers

You can't do this from XML, XML supports only strings for view tags.

like image 66
Romain Guy Avatar answered Oct 31 '22 15:10

Romain Guy


Actually you can do that if you define tag elements as a child for views. Define multiple Tag attribute for View in xml layouts

<View ...>
     <tag android:id="@+id/mytag"
          android:value="@string/mytag_value" />
 </View>
like image 37
Kaloglu Avatar answered Oct 31 '22 16:10

Kaloglu