开发者

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

开发者 https://www.devze.com 2023-02-13 15:43 出处:网络
I want to bind some extra data with a view. I am using tag in my xml file to add the extra information.

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 ??


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


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消