嘿伙计们,我有一个视图支架 + 一个基本适配器,但它不起作用
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
// get the selected entry
AI entry = (AI) mListAppInfo.get(position);
// inflate new layout if null
if(v == null) {
holder = new ViewHolder();
v = inflater.inflate(R.layout.list, null);
holder.position = position;
holder.title = (TextView)v.findViewById(R.id.tvName);
holder.icon = (ImageView)v.findViewById(R.id.ivIcon);
holder.iconimg = entry.icon;
new ThumbnailTask(position, holder)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
v.setTag(holder);
}else{
holder = (ViewHolder) v.getTag();
}
holder.title.setText(entry.title);
// return view
return v;
}
列表中的项目没有显示任何我做错了什么?
编辑这是全班
public class AIAdapter extends BaseAdapter {
private Context mContext;
private List<?> mListAppInfo;
private LayoutInflater inflater;
public AIAdapter(Context c, List<?> list, PackageManager pm) {
mContext = c;
mListAppInfo = list;
inflater = LayoutInflater.from(mContext);
}
@Override
public int getCount() {
return mListAppInfo.size();
}
@Override
public Object getItem(int position) {
return mListAppInfo.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressWarnings("null")
@Override
public View getView(int position, View v, ViewGroup parent) {
ViewHolder holder;
// get the selected entry
AI entry = (AI) mListAppInfo.get(position);
// inflate new layout if null
if(v == null) {
holder = new ViewHolder();
v = inflater.inflate(R.layout.list, null);
holder.position = position;
holder.title = (TextView)v.findViewById(R.id.tvName);
holder.icon = (ImageView)v.findViewById(R.id.ivIcon);
holder.iconimg = entry.icon;
new ThumbnailTask(position, holder)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
v.setTag(holder);
}else{
holder = (ViewHolder) v.getTag();
}
holder.title.setText(entry.title);
// return view
return v;
}
@SuppressWarnings("rawtypes")
private static class ThumbnailTask extends AsyncTask{
private int mPosition;
private ViewHolder mHolder;
private Rect mOldBounds = new Rect();
public ThumbnailTask(int position, ViewHolder holder) {
mPosition = position;
mHolder = holder;
}
@Override
protected Drawable doInBackground(Object... arg0) {
Drawable icon = mHolder.iconimg;
int width = 64;
int height = 64;
final int iconWidth = icon.getIntrinsicWidth();
final int iconHeight = icon.getIntrinsicHeight();
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
painter.setIntrinsicHeight(height);
}
if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
final float ratio = (float) iconWidth / iconHeight;
if (iconWidth > iconHeight) {
height = (int) (width / ratio);
} else if (iconHeight > iconWidth) {
width = (int) (height * ratio);
}
final Bitmap.Config c =
icon.getOpacity() != PixelFormat.OPAQUE ?
Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
final Bitmap thumb = Bitmap.createBitmap(width, height, c);
final Canvas canvas = new Canvas(thumb);
canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
mOldBounds.set(icon.getBounds());
icon.setBounds(0, 0, width, height);
icon.draw(canvas);
icon.setBounds(mOldBounds);
icon = new BitmapDrawable(thumb);
}
return icon;
}
protected void onPostExecute(Drawable bitmap) {
if (mHolder.position == mPosition) {
mHolder.icon.setImageDrawable(bitmap);
}
}
}
}
class ViewHolder{
public int position;
public TextView title;
public ImageView icon;
public Drawable iconimg;
}
我不知道我做错了什么。所有 entry.title 和 entry.icon 都有数据。虽然列表视图上没有显示任何内容。布局列表确实有一个 imageview 和 textview。这在没有查看器的情况下有效,但是一旦我添加了查看器,它就不会