我有这样的布局-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Linearlaout which acts as ListView in this case -->
<LinearLayout
android:id="@+id/Main_View_Reference"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:contentDescription="This is a container reference for main list items"
</LinearLayout>
</ScrollView>
还有另一个布局,用来放大这个布局的“线性布局”部分,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:id="@+id/Level_3_Layout"
android:orientation="vertical" >
<TextView
android:id="@+id/Level_3_Item_Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_light"
android:text="Itame Name"
android:textColor="@android:color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/Level_3_Item_Price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_light"
android:text="Item Price"
android:textColor="@android:color/black"
android:textSize="13sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
</LinearLayout>
我想做的是为从第二部分创建的动态充气布局分配一个标记值。
所以,我想用Java来为每个创建的(膨胀的)布局设置额外的隐藏信息,以存储一些额外的信息,以便下次在我需要它们时像HTML的隐藏字段那样重新检索它们。
安卓有什么办法吗?
谢谢你的帮助。
最佳答案
我不太清楚你说的“动态”是什么意思,但我想你不仅要分配值,还要为你的“隐藏字段”分配密钥。
如果我的假设是正确的,那么您可以使用以下方法:
yourView.setTag(int id, Object object);
我知道您不愿意使用
setTag
,但在这个用例中,我认为这是最适合做的事情。不过,请注意int id
,使用它可以根据需要分配任意标记(只要它们都拥有不同的id),从而使其非常动态。如果要检索使用上述方法分配的标记,请调用:
yourView.getTag(int id);
希望这有帮助!
如果这仍然不是您想要的,恐怕唯一的选择是扩展您想要的
View
,然后根据您的需要定制它。