Android 台灣中文網
標題: Android之ListView,ArrayAdpater綁定ArrayList [打印本頁]
作者: 暗桌之光 時間: 2011-7-31 13:52
標題: Android之ListView,ArrayAdpater綁定ArrayList
在Anroid開發中經常會用到ListView控件來綁定要顯示的數據,那麼如何綁定數據,我們可以通過ArrayList和ArrayAdapter來綁定數據
1.首先定義main.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"
- >
- <EditText
- android:id="@+id/edit"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- <ListView
- android:id="@+id/list"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- ></ListView>
- </LinearLayout>
複製代碼 佈局中定義了一個EditText控件(用來增加ListView項目)和ListView控件(用來顯示增加的每一項)
佈局顯示如下: