ArrayAdapter和BaseAdapter的區別

那麼對於ArrayAdapter到底比BaseAdapter先進到哪裏呢?從名稱來看Array我們可以聯繫到數組的很多操作,沒錯Android123給大家列出本類所有成員方法實用的處理方式,

比如
void  add(T object)  //添加一個對象到本ArrayAdapter
void  clear()  //清除所有元素
static ArrayAdapter<CharSequence>  createFromResource(Context context, int textArrayResId, int textViewResId)   //從layout資源構造arrayadapter Context  getContext()  //獲取實例
int  getCount() 
View  getDropDownView(int position, View convertView, ViewGroup parent)  //獲取drop down的popup風格選擇條目的內容,參數1是位置,參數2可以通過強制轉換直接獲取本條的內容
Filter  getFilter() //使用正則過濾數據
T  getItem(int position)  //獲取單條內容
long  getItemId(int position) 
int  getPosition(T item) //通過內容獲取是某條
View  getView(int position, View convertView, ViewGroup parent) 
void  insert(T object, int index)  //插入新條目到數組的index位置
void  notifyDataSetChanged()  //通知數據變化了,告訴綁定Adapter的widget來更新UI
void  remove(T object)  //移出一條從數組,這裏並沒有指定位置
void  setDropDownViewResource(int resource)  //設置dropdown的layout風格
Sets the layout resource to create the drop down views.
void  setNotifyOnChange(boolean notifyOnChange)  //本條是arrayadapter最強大的功能,android123強烈推薦處理大數據時使用該方法,可以降低ui的處理量,刷新ui可以更快速,主要可以停止對
(add(T), insert(T, int), remove(T), clear() 的操作,當然可以通過 notifyDataSetChanged(). 或 setNotifyOnChange(true) 通知變化
void  sort(Comparator<? super T> comparator)  //這裏是android開發網經常用的排序,使用arrayadapter可以直接排序,十分方便

所以最終android123推薦大傢什麼情況使用arrayadapter,什麼時候使用baseadapter。當數量較多,比如超過100條或頻繁動態增減時使用arrayadapter可以方便控制ui,通過setNotifyOnChanage方法,如果比較簡單僅僅呈現直接從baseadapter更節省資源

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章