Adapter分為底下幾種類型,用於連接不同形式的資料來源。
ArrayAdapter<T> | A concrete BaseAdapter that is backed by an array of arbitrary objects. |
BaseAdapter | Common base class of common implementation for an Adapter that can be used in both ListView (by implementing the specialized ListAdapter interface) and Spinner (by implementing the specialized SpinnerAdapter interface). |
CursorAdapter | Static library support version of the framework's CursorAdapter . |
HeaderViewListAdapter | ListAdapter used when a ListView has header views. |
ListAdapter | Extended Adapter that is the bridge between a ListView and the data that backs the list. |
ResourceCursorAdapter | Static library support version of the framework's ResourceCursorAdapter . |
SimpleAdapter | An easy adapter to map static data to views defined in an XML file. |
SimpleCursorAdapter | Static library support version of the framework's SimpleCursorAdapter . |
SpinnerAdapter | Extended Adapter that is the bridge between a Spinner and its data. |
WrapperListAdapter | List adapter that wraps another list adapter. |
使用範例:
ArrayAdapter<String> Adapter_note = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, note_array);
setListAdapter(Adapter_note); //Bind to Adapter
要先New一個ArrayAdapter物件,輸入三個參數
1. this 表示目前的Activity
2. android.R.layout.simple_list_item_1 要轉換成的格式
3. note_array 資料來源
透過 getListView().setEmptyView(findViewById(R.id.empty)); 可以顯示當List為空時要顯示的內容。
沒有留言:
張貼留言