2015-05-03 2 views
0

У меня есть линейная компоновка, содержащая несколько виджетов. Я хочу заполнить его, используя ArrayList. Я не хочу использовать listview, потому что он не работает в scrollview.Как заполнить линейный макет с помощью arraylist?

<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> 
+0

вы должны просто итерацию через ваш массив и использовать 'yourLinearLayout.addView (пункт),' –

+0

макет надуйте с помощью 'LayoutInflater' –

+0

любой пример, как это сделать. .... будет полезно –

ответ

1

Ниже пути

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); 
    } 
Смежные вопросы