gpt4 book ai didi

java - 如何使用 arraylist 填充线性布局?

转载 作者:行者123 更新时间:2023-12-01 11:35:47 25 4
gpt4 key购买 nike

我有一个包含多个小部件的线性布局。我想使用 ArrayList 来填充它。我不想使用 ListView ,因为它在 ScrollView 中不起作用。

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10" >

<TextView
android:id="@+id/xxxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="top|left"
/>

<TextView
android:id="@+id/tv_xxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:text="jshadb" />

<TextView
android:id="@+id/tv_xxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="464.89" />

<EditText
android:id="@+id/et_xxxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:hint=""
android:ems="10"
android:inputType="number" />

</LinearLayout>

最佳答案

在路下面

LayoutInflater linf = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
linf = LayoutInflater.from(YourActivity.this);

//Linear Layout on you want to add inflated View
LinearLayout tbl_layout=(LinearLayout)findViewById(R.id.Layoutid);

for (int i = 0; i < arrayList.size(); i++) {

View v = linf.inflate(R.layout.YourLinearLayout, null);//Pass your lineraLayout

((TextView) v.findViewById(R.id.xxxx)).setText("textS");

tbl_layout.addView(v);
}

关于java - 如何使用 arraylist 填充线性布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30010587/

25 4 0