本文实例讲述了AndroID编程实现在adapter中进行数据 *** 作的方法。分享给大家供大家参考,具体如下:
package com.cvte.apkclassify;import java.util.ArrayList;import androID.content.Context;import androID.content.pm.ApplicationInfo;import androID.content.pm.PackageInfo;import androID.content.pm.PackageManager;import androID.content.pm.PackageManager.nameNotFoundException;import androID.graphics.drawable.Drawable;import androID.util.Log;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.BaseAdapter;import androID.Widget.ImageVIEw;import androID.Widget.TextVIEw;public class ItemAdapter extends BaseAdapter { private Context context; private LayoutInflater inflater; private PackageManager pManager ; private ArrayList<PackageInfo> apps; private ArrayList<ApkBean> allApkBeans; private ApkBean bean = new ApkBean(); private dbutils utils ; private ApplicationInfo appinfo; private static int ll = 1; public ItemAdapter(Context c) { super(); this.context = c; pManager = context.getPackageManager(); apps = (ArrayList<PackageInfo>) GetAllAppInfo.getAllapps(context); utils = new dbutils(context); allApkBeans = (ArrayList<ApkBean>) utils.getAllRecords(); for (int i = 0; i < apps.size(); i++) { bean = new ApkBean(); bean.setApkname(pManager.getApplicationLabel(apps.get(i).applicationInfo).toString()); bean.setKind(0); bean.setPackagename(apps.get(i).applicationInfo.packagename); utils.insert(bean); } } @OverrIDe public int getCount() { // Todo auto-generated method stub return apps.size(); } @OverrIDe public Object getItem(int position) { // Todo auto-generated method stub return apps.get(position); } @OverrIDe public long getItemID(int position) { // Todo auto-generated method stub return 0; } @OverrIDe public VIEw getVIEw(int position,VIEw vIEw,VIEwGroup parent) { VIEwHolder holder = null; inflater = LayoutInflater.from(context); if (vIEw==null) { holder = new VIEwHolder(); vIEw = inflater.inflate(R.layout.Listitem,null); holder.apkimage = (ImageVIEw)vIEw.findVIEwByID(R.ID.apkimage); holder.apkname =(TextVIEw)vIEw.findVIEwByID(R.ID.apkname); holder.result = (TextVIEw)vIEw.findVIEwByID(R.ID.result); vIEw.setTag(holder); }else{ holder=(VIEwHolder)vIEw.getTag(); } if (allApkBeans==null||allApkBeans.size()==0) { PackageInfo pinfo = apps.get(position); String name = pManager.getApplicationLabel(pinfo.applicationInfo).toString(); holder.apkimage.setBackgroundDrawable(pManager.getApplicationIcon(pinfo.applicationInfo)); holder.apkname.setText(name); holder.result.setText("未分类"); }else{ ApkBean bean = allApkBeans.get(position); holder.apkimage.setBackgroundDrawable( getIconFromPackagename(bean.getPackagename())); holder.apkname.setText(bean.getApkname()); if (bean.getKind()!=0) { holder.result.setText("已经分类"); }else{ holder.result.setText("未分类"); } } return vIEw; } class VIEwHolder{ public ImageVIEw apkimage; public TextVIEw apkname; public TextVIEw result; } private Drawable getIconFromPackagename(String name){ Drawable image = null ; try { appinfo = pManager.getApplicationInfo(name,PackageManager.GET_Meta_DATA); image = pManager.getApplicationIcon(appinfo); } catch (nameNotFoundException e) { Log.i("no packagename","no packagename"); } return image; }}
更多关于AndroID相关内容感兴趣的读者可查看本站专题:《Android数据库 *** 作技巧总结》、《Android编程之activity *** 作技巧总结》、《Android文件 *** 作技巧汇总》、《Android编程开发之SD卡 *** 作方法汇总》、《Android开发入门与进阶教程》、《Android资源 *** 作技巧汇总》、《Android视图View技巧总结》及《Android控件用法总结》
希望本文所述对大家AndroID程序设计有所帮助。
总结以上是内存溢出为你收集整理的Android编程实现在adapter中进行数据 *** 作的方法全部内容,希望文章能够帮你解决Android编程实现在adapter中进行数据 *** 作的方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)