繁体   English   中英

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

[英]How to populate a linear layout using arraylist?

我有一个线性布局,其中包含多个小部件。 我想使用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);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM