最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中BaseAdapter用法示例

 更新時間:2016年08月18日 09:27:00   作者:與時俱進  
這篇文章主要介紹了Android中BaseAdapter用法,分析了BaseAdapter的功能、使用方法與相關(guān)注意事項,需要的朋友可以參考下

本文實例講述了Android中BaseAdapter用法。分享給大家供大家參考,具體如下:

概述:

BaseAdapter就Android應(yīng)用程序中經(jīng)常用到的基礎(chǔ)數(shù)據(jù)適配器,它的主要用途是將一組數(shù)據(jù)傳到像ListView、Spinner、Gallery及GridView等UI顯示組件,它是繼承自接口類Adapter

BaseAdapter

Java代碼:

public class RecentAdapter extends BaseAdapter {
  private class RecentViewHolder {
    TextView appName;
    ImageView appIcon;
    TextView appSize;
  }
  private List<ResolveInfo> mAppList;
  private LayoutInflater mInflater;
  private PackageManager pm;
  public RecentAdapter(Context c, List<ResolveInfo> appList,
      PackageManager pm) {
    mAppList = appList;
    this.pm = pm;
    mInflater = (LayoutInflater) c
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  public void clear(){
    if(mAppList!=null){
      mAppList.clear();
    }
  }
  public int getCount() {
    return mAppList.size();
  }
  @Override
  public Object getItem(int position) {
    return mAppList.get(position);
  }
  @Override
  public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
  }
  public View getView(int position, View convertView, ViewGroup parent) {
    RecentViewHolder holder;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.app_info_item, null);
      holder = new RecentViewHolder();
      holder.appName = (TextView) convertView.findViewById(R.id.app_name);
      holder.appIcon = (ImageView) convertView
          .findViewById(R.id.app_icon);
      holder.appSize = (TextView) convertView.findViewById(R.id.app_size);
      convertView.setTag(holder);
    } else {
      holder = (RecentViewHolder) convertView.getTag();
    }
    ResolveInfo appInfo = mAppList.get(position);
    if (appInfo != null) {
      String labelName = appInfo.loadLabel(pm).toString();
      if (labelName != null) {
        holder.appName.setText(labelName);
      }
      Drawable icon = appInfo.loadIcon(pm);
      if (icon != null) {
        holder.appIcon.setImageDrawable(icon);
      }
    }
    return convertView;
  }
  public void remove(int position){
    mAppList.remove(position);
    this.notifyDataSetChanged();
  }
}

其中兩個注意點為:

setTag 用View設(shè)置存儲數(shù)據(jù)

notifyDataSetChanged() 告訴View數(shù)據(jù)更改并刷新

View convertView = mInflater.inflate(R.layout.app_info_item, null)  加載XML Item 視圖

app_info_item.xml文件示例:

xml代碼:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="wrap_content"
  android:layout_gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight">
  <ImageView android:id="@+id/app_icon" android:layout_width="@android:dimen/app_icon_size"
    android:layout_height="@android:dimen/app_icon_size"
    android:layout_alignParentLeft="true" android:paddingLeft="6dip"
    android:paddingTop="6dip" android:paddingBottom="6dip"
    android:scaleType="fitCenter" />
  <TextView android:id="@+id/app_name" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="?android:attr/textColorPrimary"
    android:layout_toRightOf="@id/app_icon" android:paddingLeft="6dip"
    android:paddingTop="6dip" />
  <TextView android:id="@+id/app_description"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:layout_below="@+id/app_name" android:layout_toRightOf="@id/app_icon"
    android:paddingLeft="6dip" android:paddingBottom="6dip" />
  <TextView android:id="@+id/app_size" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall"
    android:layout_alignParentRight="true" android:layout_below="@+id/app_name"
    android:paddingRight="6dip" android:maxLines="1" />
</RelativeLayout>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進階教程》及《Android資源操作技巧匯總

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • 如何在WorkManager中處理異步任務(wù)詳解

    如何在WorkManager中處理異步任務(wù)詳解

    這篇文章主要給大家介紹了關(guān)于如何在WorkManager中處理異步任務(wù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • Android中WebView加載的網(wǎng)頁被放大的解決辦法

    Android中WebView加載的網(wǎng)頁被放大的解決辦法

    這篇文章主要介紹了Android中WebView加載的網(wǎng)頁被放大的問題的解決辦法,非常不錯,具有參考借鑒價值,需要的朋友參考下
    2016-12-12
  • Android 多渠道打包進階版

    Android 多渠道打包進階版

    上篇文章更了Android 多渠道打包,這篇文章將做一個后續(xù)繼續(xù)更Android 多渠道打包進階版,上次意未盡的朋友可以繼續(xù)啦,第一次點進來的朋友也可以看上次文章
    2021-09-09
  • Android視頻壓縮的示例代碼

    Android視頻壓縮的示例代碼

    本篇文章主要介紹了Android視頻壓縮的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • Android自定義View之酷炫圓環(huán)(二)

    Android自定義View之酷炫圓環(huán)(二)

    這篇文章主要介紹了Android自定義View之酷炫圓環(huán),本文是第二篇針對Android圓環(huán)實現(xiàn)方法進行的詳細闡述,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android中EditText光標的顯示與隱藏方法

    Android中EditText光標的顯示與隱藏方法

    這篇文章主要給大家介紹了關(guān)于Android中EditText光標的顯示與隱藏以及Android之第一次不顯示EditText光標的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2021-11-11
  • 詳解Flutter中key的正確使用方式

    詳解Flutter中key的正確使用方式

    這篇文章主要為大家介紹了詳解Flutter中key的正確使用方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Android學(xué)習(xí)之Fragment

    Android學(xué)習(xí)之Fragment

    Fragment是什么?碎片(Fragment)是一種可以嵌入在活動(activity)當(dāng)中的UI片段,想要了解碎片的簡單用法的朋友可以參考一下
    2016-01-01
  • android使用webwiew載入頁面使用示例(Hybrid App開發(fā))

    android使用webwiew載入頁面使用示例(Hybrid App開發(fā))

    Hybrid App 融合 Web App 的原理就是嵌入一個WebView組件,可以在這個組件中載入頁面,相當(dāng)于內(nèi)嵌的瀏覽器,下面是使用示例
    2014-03-03
  • Android中絕對音量和相對音量設(shè)置

    Android中絕對音量和相對音量設(shè)置

    大家好,本篇文章主要講的是Android中絕對音量和相對音量設(shè)置,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-01-01

最新評論

卓尼县| 莱西市| 恩平市| 浮山县| 闻喜县| 郸城县| 广饶县| 阳谷县| 高雄县| 营口市| 余庆县| 汾阳市| 塔城市| 澜沧| 安泽县| 云霄县| 子洲县| 伊金霍洛旗| 思茅市| 曲周县| 洞头县| 瑞安市| 子长县| 深圳市| 秦安县| 富裕县| 延川县| 石城县| 称多县| 北海市| 香港 | 丰台区| 平和县| 西乡县| 嘉黎县| 苍南县| 彭山县| 大荔县| 清远市| 株洲县| 滨海县|