public void initView(ApkBean data, int position) { this.bean = data; this.mPosition = position; this.implInfo = implAgent.getImplInfo( data.getPackageName(), data.getPackageName(), data.getVersionCode()); if (null != this.implInfo) { this.implInfo .setDownloadUrl(data.getrDownloadUrl()) .setIconUrl(data.getIconUrl()) .setTitle(data.getName()); implAgent.bindImplCallback(this, implInfo); } mBt.setTag(this); refresh(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewholder; /* 将convertView封装在ViewHodler中,减少系统内存占用 */ if (convertView == null) { /* convertView为空则初始化 */ convertView = mInflater.inflate(R.layout.item_preload_listview, parent, false); viewholder = new ViewHolder(convertView); convertView.setTag(viewholder); } else { // 不为空则直接使用已有的封装类 viewholder = (ViewHolder) convertView.getTag(); } final ApkBean data = mPreloadData.get(position); viewholder.initView(data, position); if (position + 1 > SHOW_ICON_NUMBER) { viewholder.mSize.setVisibility(View.GONE); viewholder.mBt.setVisibility(View.GONE); viewholder.mIcon.setVisibility(View.GONE); viewholder.mClickItem.setClickable(false); viewholder.mName.setPadding(20, 10, 10, 10); } else { viewholder.mName.setPadding(0, 0, 0, 0); viewholder.mSize.setVisibility(View.VISIBLE); viewholder.mBt.setVisibility(View.VISIBLE); viewholder.mIcon.setVisibility(View.VISIBLE); if (AppliteUtils.isLoadNetworkBitmap(mActivity)) mBitmapUtil.display(viewholder.mIcon, data.getIconUrl()); viewholder.mSize.setText(AppliteUtils.bytes2kb(data.getApkSize())); viewholder.mClickItem.setClickable(true); viewholder.mClickItem.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ((OSGIServiceHost) mActivity) .jumptoDetail( data.getPackageName(), data.getName(), data.getIconUrl(), data.getVersionCode(), null, true); } }); } viewholder.mName.setText(data.getName()); viewholder.mBt.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ViewHolder vh = (ViewHolder) v.getTag(); ImplHelper.onClick( mActivity, vh.implInfo, vh.bean.getrDownloadUrl(), vh.bean.getName(), vh.bean.getIconUrl(), Environment.getExternalStorageDirectory() + File.separator + Constant.extenStorageDirPath + vh.bean.getName() + ".apk", null, vh); } }); return convertView; }