BaseAdapter&GridView

來源:互聯網
上載者:User

Adapter是串連後端資料和最上層顯示的適配器介面,是資料和UI(View)之間一個重要的紐帶。在常見的View(ListView,GridView)等地方都需要用到Adapter。如直觀的表達了Data、Adapter、View三者的關係:


BaseAdapter是一個abstrace class要使用時必須重寫他的方法,注意這些方法都是抽象方法,分別生命在Adapter abstrace class中。分別是:

public int getCount()返回該Adapter中裝載的資源的數量

public Object getItem(int position)從data set中取出指定poistion處的資料

public long getItemId(int position)return position處的item所在的row id

public View getView(int position, View convertView, ViewGroup parent)

position:data set 中position處的資料,this data we want to view.

convertView:使用之前用convertView ? null判斷,if can't covert to a view來裝載資料然後顯示的話,就需要建立一個新的view了;了;來裝載資料.

parent: as the convertView's parent view and must attached to parent.

after call this function will return the view with data in the position  of  the adapter. 

點擊時候的響應函數:

public abstract void onItemClick
(AdapterView<?> parent,

View view, int position, long id)

parent The AdapterView where the click happened.發生click事件的那個AdapterView
view The view within the AdapterView that was clicked (this will be a view provided by the adapter)
position The position of the view in the adapter.
id The row id of the item that was clicked. 

ImageSwitcher:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.