开发者

Weird issue: Gallery Widget never calls getView

开发者 https://www.devze.com 2023-01-09 15:05 出处:网络
I am working on a media player for an example application... and things are moving along great... except that when I add my AlbumAdapter to the Gallery Widget... it never calls getView.

I am working on a media player for an example application... and things are moving along great... except that when I add my AlbumAdapter to the Gallery Widget... it never calls getView.

Isn't this right?

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());

There are 13 items in the adapter... I checked. No call to getView is ever made... I have a Log item there that never gets called.

Here is my Adapter class

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;
    }

Here is the log:

08-02 01:10:46.821: VERBOSE/Album:(562): Adding Alice In Chains Alice In Chains

08-02 01:10:46.821: VERBOSE/Album:(562): Adding Alice In Chains Black Gives Way To Blue 08-02 01:10:46.821: VERBOSE/Album:(562): Adding Alter Bridge Blackbird 08-02 01:10:46.831: VERBOSE/Album:(562): Adding Alice In Chains Dirt 08-02 01:10:46.831: VERBOSE/Album:(562): Adding Alice In Chains Facelift 08-02 01:10:46.831: VERBOSE/Album:(562): Adding Alice In Chains Jar Of Flies 08-02 01:10:46.831: VERBOSE/Album:(562): Adding August Burns Red Messengers 08-02 01:10:46.831: VERBOSE/Album:(562): Adding As I Lay Dying An Ocean Between Us 08-02 01:10:46.831: VERBOSE/Album:(562): Adding Alter Bridge One Day Remains 08-02 01:10:46.842: VERBOSE/Album:(562): Adding Alice In Chains SAP 08-02 01:10:46.852: VERBOSE/Album:(562): Adding As I Lay Dying Shadows Are Security 08-02 01:10:46.852: VERBOSE/Album:(562): Adding August Burns Red Thrill Seeker 08-02 01:10:46.852: VERBOSE/Album:(562): Adding Alice In Chains Unplugged 08-02 01:10:46.871: VERBOSE/Log(562): got here

08-02 01:10:49.311: VERBOSE/coverImageAdapter(562): Count is: 13

08-02 01:10:49.321: VERBOSE/Gallery(562): Object: android.widget.Gallery@439558c0 Child count: 0

08-02 01:10:49.571: INFO/ActivityManager(222): Displayed activity com.androidworkz.andamp/.andAMP: 4062 ms (total 4062 ms)


It looks like your Gallery view is not added to the window, or has a size of 0.

0

精彩评论

暂无评论...
验证码 换一张
取 消