我想從foreach循環中添加項目。我的問題是,無論我添加多少,我只能看到一個項目。我在下面做了一個示例代碼,其中有我的問題。從我的佈局開始。listview只顯示一個項目
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:focusableInTouchMode="true">
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:focusableInTouchMode="true">
<TextView
android:textSize="10pt"
android:id="@+id/HeaderLbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="7pt"
android:id="@+id/ErrorLbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffff0000"
/>
<Spinner
android:id="@+id/OrderSpinner"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
</Spinner>
<TextView
android:textSize="8pt"
android:id="@+id/OrderRef"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="7pt"
android:id="@+id/OrderDateTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="7pt"
android:id="@+id/OrderCustomer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="7pt"
android:id="@+id/OrderInnerComment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Spinner
android:id="@+id/ArticleSpinner"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
</Spinner>
<ListView
android:id="@+id/OperationsListView"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
在這裏,我模擬我的foreach循環添加項目。
ArrayAdapter CalculationAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1);
ListView OperationsListView = FindViewById<ListView>(Resource.Id.OperationsListView);
for (int i = 0; i < 3; i++)
{
CalculationAdapter.Add(i.ToString());
}
OperationsListView.Adapter = CalculationAdapter;
幫助最受讚賞!謝謝。編輯: 我認爲scrollview是問題。
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
我刪除它,然後它的工作:) 不爲什麼壽明白.. How can I put a ListView into a ScrollView without it collapsing? Mabye這可以幫助其他任何具有相同的概率
你在哪裏設置適配器到列表視圖? –
OperationsListView.Adapter = CalculationAdapter;對? – Serik