freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

android開發(fā)技巧總匯android開發(fā)培訓(xùn)-教師必備-閱讀頁

2025-05-01 12:27本頁面
  

【正文】 的字符串,圖片,或者基本組件。SimpleAdapter有最好的擴(kuò)充性,可以自定義出各種效果。我們從最簡單的ListView開始: /*** author allin**/public class MyListView extends Activity {private ListView listView。Overridepublic void onCreate(Bundle savedInstanceState){ (savedInstanceState)。 (new ArrayAdapterString(this, ,getData()))。}private ListString getData(){ ListString data = new ArrayListString()。 (測試數(shù)據(jù)2)。 (測試數(shù)據(jù)4)。}}復(fù)制代碼上面代碼使用了ArrayAdapter(Context context, int textViewResourceId, ListT objects)來裝配數(shù)據(jù),要裝配這些數(shù)據(jù)就需要一個連接ListView視圖對象和數(shù)組數(shù)據(jù)的適配器來兩者的適配工作,ArrayAdapter的構(gòu)造需要三個參數(shù),依次為this,布局文件(注意這里的布局文件描述的是列表的每一行的布局,數(shù)據(jù)源(一個List集合)。運行后的現(xiàn)實結(jié)構(gòu)如下圖: SimpleCursorAdapter  sdk的解釋是這樣的:An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views?! ∠旅娴某绦蚴菑碾娫挷局邪崖?lián)系人顯示到類表中。然后獲得一個指向數(shù)據(jù)庫的Cursor并且定義一個布局文件(當(dāng)然也可以使用系統(tǒng)自帶的)。//private ListString data = new ArrayListString()。 listView = new ListView(this)。 startManagingCursor(cursor)。 (listAdapter)。}}復(fù)制代碼 Cursor cursor = getContentResolver().query(, null, null, null, null)?!tartManagingCursor(cursor)?!impleCursorAdapter 構(gòu)造函數(shù)前面3個參數(shù)和ArrayAdapter是一樣的,最后兩個參數(shù):一個包含數(shù)據(jù)庫的列的String型數(shù)組,一個包含布局文件中對應(yīng)組件id的int型數(shù)組。上面的代碼,將NAME列的數(shù)據(jù)一次映射到布局文件的id為text1的組件上。下面的代碼都直接繼承了ListActivity,ListActivity和普通的Activity沒有太大的差別,不同就是對顯示ListView做了許多優(yōu)化,方面顯示而已。首先需要定義好一個用來顯示每一個列內(nèi)容的xml ?xml version= encoding=utf8?LinearLayout xmlns:android=android:orientation=horizontal android:layout_width=fill_parentandroid:layout_height=fill_parentImageView android:id=+id/img android:layout_width=wrap_content android:layout_height=wrap_content android:layout_margin=5px/LinearLayout android:orientation=vertical android:layout_width=wrap_content android:layout_height=wrap_content TextView android:id=+id/title android:layout_width=wrap_content android:layout_height=wrap_content android:textColor=FFFFFFFF android:textSize=22px / TextView android:id=+id/info android:layout_width=wrap_content android:layout_height=wrap_content android:textColor=FFFFFFFF android:textSize=13px //LinearLayout/LinearLayout復(fù)制代碼下面是實現(xiàn)代碼: /*** author allin* */public class MyListView3 extends ListActivity {// private ListString data = new ArrayListString()。 SimpleAdapter adapter = new SimpleAdapter(this,getData(), new String[]{title,info,img}, new int[]{,})。}private ListMapString, Object getData() { ListMapString, Object list = new ArrayListMapString, Object()。 (title, G1)。 (img, )。 map = new HashMapString, Object()。 (info, google 2)。 (map)。 (title, G3)。 (img, )。 return list。HashMap的每個鍵值數(shù)據(jù)映射到布局文件中對應(yīng)id的組件上。下面做適配,new一個SimpleAdapter參數(shù)一次是:this,布局文件(),HashMap的 title 和 info,img。布局文件的各組件分別映射到HashMap的各元素上,完成適配。添加按鈕首先要寫一個有按鈕的xml文件,然后自然會想到用上面的方法定義一個適配器,然后將數(shù)據(jù)映射到布局文件上。下面的示例將顯示一個按鈕和一個圖片,兩行字如果單擊按鈕將刪除此按鈕的所在行。效果如下: ?xml version= encoding=utf8?LinearLayout xmlns:android=android:orientation=horizontal android:layout_width=fill_parentandroid:layout_height=fill_parentImageView android:id=+id/img android:layout_width=wrap_content android:layout_height=wrap_content android:layout_margin=5px/LinearLayout android:orientation=vertical android:layout_width=wrap_content android:layout_height=wrap_content TextView android:id=+id/title android:layout_width=wrap_content android:layout_height=wrap_content android:textColor=FFFFFFFF android:textSize=22px / TextView android:id=+id/info android:layout_width=wrap_content android:layout_height=wrap_content android:textColor=FFFFFFFF android:textSize=13px //LinearLayoutButton android:id=+id/view_btn android:layout_width=wrap_content android:layout_height=wrap_content android:text=string/s_view_btn android:layout_gravity=bottom|right //LinearLayout復(fù)制代碼程序代碼: /*** author allin* */public class MyListView4 extends ListActivity {private ListMapString, Object mData。 mData = getData()。 setListAdapter(adapter)。 MapString, Object map = new HashMapString, Object()。 (info, google 1)。 (map)。 (title, G2)。 (img, )。 map = new HashMapString, Object()。 (info, google 3)。 (map)。}// ListView 中某項被選中后的邏輯Overrideprotected void onListItemClick(ListView l, View v, int position, long id) { (MyListView4click, (String)(position).get(title))。}public final class ViewHolder{ public ImageView img。 public TextView info。}public class MyAdapter extends BaseAdapter{ private LayoutInflater mInflater。 } Override public int getCount() { // TODO Autogenerated method stub return ()。 } Override public long getItemId(int arg0) { // TODO Autogenerated method stub return 0。 if (convertView == null) { holder=new ViewHolder()。 = (ImageView)()。 = (TextView)()。 (holder)。 } ((Integer)(position).get(img))。 ((String)(position).get(info))。 } })。 }}} 復(fù)制代碼  下面將對上述代碼,做詳細(xì)的解釋,listView在開始繪制的時候,系統(tǒng)首先調(diào)用getCount()函數(shù),根據(jù)他的返回值得到listView的長度(這也是為什么在開始的第一張圖特別的標(biāo)出列表長度),然后根據(jù)這個長度,調(diào)用getView()逐一繪制每一行?! ∠到y(tǒng)顯示列表時,首先實例化一個適配器(這里將實例化自定義的適配器)。系統(tǒng)在繪制列表的每一行的時候?qū)⒄{(diào)用此方法。然后將xml文件中的各個組件實例化(簡單的findViewById()方法)。但是按鈕為了響應(yīng)點擊事件,需要為它添加點擊監(jiān)聽器,這樣就能捕獲點擊事件。系統(tǒng)要繪制ListView了,他首先獲得要繪制的這個列表的長度,然后開始繪制第一行,怎么繪制呢?調(diào)用getView()函數(shù)。好了,繪制完這一行了。在實際的運行過程中會發(fā)現(xiàn)listView的每一行沒有焦點了,這是因為Button搶奪了listView的焦點,只要布局文件中將Button設(shè)置為沒有焦點就OK了。CursorAdapter主要正對數(shù)據(jù)庫使用,下面通過例子介紹ArrayAdapter ,SimpleAdapter的簡單使用: 1:ArrayAdapter 它接受一個數(shù)組或者List作為參數(shù)
點擊復(fù)制文檔內(nèi)容
教學(xué)教案相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1