74.
public class APKAdapter extends BaseAdapter {
List<AppsInfo> mAppsInfoList = new ArrayList<AppsInfo>();
Context mContext;
public APKAdapter(List<AppsInfo> mAppsInfoList, Context mContext) {
this.mAppsInfoList = mAppsInfoList;
this.mContext = mContext;
}
public int getCount() {
return mAppsInfoList.size();
}
public Object getItem(int position) {
return mAppsInfoList.get(position);
}
public long getItemId(int position) {
return position;
}
75.
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
View view = null;
//1.当 covertView 为空时(第一次调用)
if (convertView == null){
//1.获取布局加载器
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
//2.获取 view 对象
view = layoutInflater.inflate(R.layout.item,null);
//3.获取 item 中的控件对象
viewHolder = new ViewHolder(view);
view.setTag(viewHolder);
}else {
view = convertView;
viewHolder = (ViewHolder) view.getTag();
}
AppsInfo appsInfo = (AppsInfo) getItem(position);
viewHolder.mImIcon.setImageDrawable(appsInfo.getDrIcon());
viewHolder.mTvAppName.setText(appsInfo.getStrApkName());
viewHolder.mTvAppPackge.setText(appsInfo.getStrPackageName());
return view;
}
76.
public class ViewHolder{
ImageView mImIcon = null;
TextView mTvAppName = null;
TextView mTvAppPackge = null;
public ViewHolder(View view){
mImIcon = (ImageView) view.findViewById(R.id.im_icon);
mTvAppName = (TextView) view.findViewById(R.id.tv_appname);
mTvAppPackge = (TextView) view.findViewById(R.id.tv_apppackge);
}