我想做一個程序,它有一個listview的小部件,它顯示了我從數據庫中獲取的一些項目。我爲我的listview設置了一個arrayadapter,它顯示了元素,但不向下或向上滾動。這是我的代碼,順便說一句,我使用的是Android 2.3.3 avd。我的android listview不滾動
ListView lv;
lv = (ListView)findViewById(R.id.listView1);
String[] liste = new String[suggestion.size()];
//liste is populated afterwards, there are about 100 items
ArrayAdapter<String> adapterForList = new ArrayAdapter<String>(getApplicationContext(),R.layout.listview,R.id.word,liste);
lv.setAdapter(adapterForList);
,這裏是我的listview.xml
<?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:padding="5dp">
<TextView
android:id="@+id/word"
style="@android:style/TextAppearance.Large"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
這裏是活動使用的主要XML文件。上面那個只是列表視圖控件。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Spinner android:id="@+id/spinner1" android:layout_width="wrap_content"
android:layout_height="wrap_content"></Spinner>
<EditText android:id="@+id/etSQL" android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
</LinearLayout>
<ListView android:layout_width="fill_parent" android:id="@+id/listView1"
android:layout_height="0dp" android:layout_weight="1"></ListView>
</LinearLayout>
其中是listview,其不是xml文件... ??? –
如果在佈局中沒有代碼缺失,則您的代碼應該導致空指針異常。沒有使用您使用的id listView1的視圖。 – Janusz
錯誤的XML文件我猜,它只包含一個帶有textview的線性佈局,在那個文件中沒有列表視圖? –