我正在为一个示例应用程序的媒体播放器工作......事情正在发生变化......除了当我将我的AlbumAdapter添加到Gallery Widget时...它从不调用getView。
这不对吗?
albumList = getAlbums(mCurrentArtist);
// updateAlbumArt();
if (albumList.size() > 0) {
Log.v("Log", "got here");
AlbumAdapter coverImageAdapter = new AlbumAdapter();
Gallery gallery = (Gallery) player.findViewById(R.id.covers);
gallery.setSpacing(5);
gallery.setAdapter(coverImageAdapter);
Log.v("coverImageAdapter", "Count is: "+coverImageAdapter.getCount());
Log.v("Gallery", "Object: "+gallery.toString()+" Child count: "+gallery.getChildCount());
适配器中有13项......我查了一下。没有调用getView ......我有一个永远不会被调用的Log项目。
这是我的Adapter类
public class AlbumAdapter extends BaseAdapter {
class ViewHolder {
ImageView cover;
}
public int getCount() {
return coverImages.size();
}
public Object getItem(int position) {
return coverImages.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
Album album;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 3;
Log.v("Gallery", "Position : "+position);
if (convertView == null) {
convertView = inflater.inflate(R.layout.cover, null);
holder = new ViewHolder();
holder.cover = (ImageView) convertView
.findViewById(R.id.albumcover);
holder.cover
.setLayoutParams(new Gallery.LayoutParams(120, 170));
holder.cover.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (position > getCount()) {
Bitmap empty = BitmapFactory.decodeResource(getResources(),
R.drawable.empty, options);
Drawable cover = new BitmapDrawable(getResources(), empty);
cover.setDither(true);
holder.cover
.setLayoutParams(new Gallery.LayoutParams(120, 170));
holder.cover.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.cover.setImageDrawable(cover);
Log.v("AlbumAdapter", "Adding cover to fill empty spot");
} else {
album = albumList.get(position);
if (album.cover == null) {
holder.cover
.setLayoutParams(new Gallery.LayoutParams(120, 170));
holder.cover.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.cover.setImageDrawable(createReflectedResource(R.drawable.albumart_unknown, album, position));
BitmapDrawable drawable = (BitmapDrawable) holder.cover
.getDrawable();
drawable.setAntiAlias(true);
Log.v("AlbumAdapter", "Missing cover... adding default");
} else {
holder.cover.setLayoutParams(new Gallery.LayoutParams(120,
170));
holder.cover
.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.cover
.setImageDrawable(coverImages.get(position));
BitmapDrawable drawable = (BitmapDrawable) holder.cover
.getDrawable();
drawable.setAntiAlias(true);
Log.v("AlbumAdapter", "adding artist cover...");
}
}
return convertView;
}
这是日志:
08-02 01:10:46.821: VERBOSE/Album:(562): Adding Alice In Chains Alice In Chains
08-02 01:10:46.821:VERBOSE /专辑:(562):在链中添加爱丽丝黑色给蓝色 08-02 01:10:46.821:VERBOSE /专辑:(562):添加Alter Bridge Blackbird 08-02 01:10:46.831:VERBOSE /专辑:(562):在链中添加爱丽丝污垢 08-02 01:10:46.831:VERBOSE /专辑:(562):添加Alice In Chain Facelift 08-02 01:10:46.831:VERBOSE /专辑:(562):在链中添加爱丽丝罐子里的苍蝇 08-02 01:10:46.831:VERBOSE /专辑:(562):加入8月烧红色信使 08-02 01:10:46.831:VERBOSE /专辑:(562):在我们之间加入一片海洋 08-02 01:10:46.831:VERBOSE /专辑:(562):添加Alter Bridge一天仍然存在 08-02 01:10:46.842:VERBOSE /专辑:(562):添加Alice In Chains SAP 08-02 01:10:46.852:VERBOSE /专辑:(562):添加,因为我躺着死亡阴影是安全 08-02 01:10:46.852:VERBOSE /专辑:(562):加入August Burns Red Thrill Seeker 08-02 01:10:46.852:VERBOSE /专辑:(562):在链中添加爱丽丝不插电 08-02 01:10:46.871:VERBOSE / Log(562):来到这里
08-02 01:10:49.311:VERBOSE / coverImageAdapter(562):伯爵是:13
08-02 01:10:49.321:VERBOSE / Gallery(562):对象:android.widget.Gallery@439558c0子女数:0
08-02 01:10:49.571:INFO / ActivityManager(222):显示的活动com.androidworkz.andamp / .andAMP:4062 ms(总计4062 ms)
答案 0 :(得分:1)
看起来您的图库视图未添加到窗口中,或者大小为0。