gpt4 book ai didi

android - 如何在 Activity 中循环一组 View ?

转载 作者:行者123 更新时间:2023-11-30 02:50:49 25 4
gpt4 key购买 nike

<TextView
android:id="@+id/tvLabel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />

<TextView
android:id="@+id/tvValue1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

我想在一个 Activity 中循环这组 View (在 java 中)。我还需要为每个 TextView 设置不同的文本。我认为可能有办法做到这一点。在布局中创建多个 textview 并不是解决此问题的好方法。请帮我解决这个问题。

最佳答案

你需要把你的textview,view,textview放到一个parent layout中(比如LinearLayout)。
然后:

LinearLayout parentLayout = (LinearLayout) findViewById(R.id.yourLayout);
for (int j = 0; j < parentLayout.getChildCount(); j++) {
View v = parentLayout.getChildAt(j);

//check and convert to comfortable view
//update text
//...

}

关于android - 如何在 Activity 中循环一组 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24220730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com