How to add many values in android:tag

浪尽此生 提交于 2019-12-12 03:53:59

问题


In Android XML, I want to add multiple values in android:tag. I found one way that we can use multiple for adding values.

<TextView   
         android:id="@+id/myTextView"   
         android:layout_width="wrap_content"   
         android:layout_height="wrap_content">
        <tag android:id="@+id/value_one" android:value="@string/value_one"/>
        <tag android:id="@+id/value_two" android:value="@string/value_two"/>
        <tag android:id="@+id/value_three" android:value="@string/value_three"/>
 </TextView>

But this method work only in API level 21 and above. The Android provides the following error while using above method.

tag is only used in API level 21 and higher (current min is 19)

In API level 19, we have an option to set tag in programmatically. Is there any other option to add multiple strings or Object in XML itself?


回答1:


The way to add extra information to a Viewis by using setTag and getTag.

What is the main purpose of setTag() getTag() methods of View?



来源:https://stackoverflow.com/questions/44673557/how-to-add-many-values-in-androidtag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!