StickyGridHeader示例

StickyGridHeader示例

我正在实现一个网格视图,其中包含每个月的标题(月)和图像。我正在尝试实现基本适配器,但它似乎不起作用。

GridView stickyGrid = (GridView) findViewById(R.id.show_gridview);
        GridViewAdapter adapter = new GridViewAdapter(getBaseContext());
        stickyGrid.setAdapter(adapter);


基本适配器实施

public class GridViewAdapter extends BaseAdapter implements
        StickyGridHeadersBaseAdapter {

    private LayoutInflater inflater;

    public GridViewAdapter(Context context) {
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        imageUrls.size();
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return imageUrls.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView holder;

        if (convertView == null) {
            holder = (ImageView) inflater.inflate(R.layout.item_grid,
                    parent, false);
        } else {
            holder = (ImageView) convertView;
        }

        imageLoader.displayImage(Util.BASE_URL + imageUrls.get(position),
                holder, options, new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        spinner.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view,
                            FailReason failReason) {
                        String message = null;
                        switch (failReason.getType()) {
                        case IO_ERROR:
                            message = "Input/Output error";
                            break;
                        case DECODING_ERROR:
                            message = "Image can't be decoded";
                            break;
                        case NETWORK_DENIED:
                            message = "Downloads are denied";
                            break;
                        case OUT_OF_MEMORY:
                            message = "Out Of Memory error";
                            break;
                        case UNKNOWN:
                            message = "Unknown error";
                            break;
                        }
                        Toast.makeText(getBaseContext(), message,
                                Toast.LENGTH_SHORT).show();
                        spinner.setVisibility(View.GONE);
                    }

                    @Override
                    public void onLoadingComplete(String imageUri,
                            View view, Bitmap loadedImage) {
                        spinner.setVisibility(View.GONE);
                    }
                });
        return holder;
    }

    @Override
    public int getCountForHeader(int arg0) {
        return datesHeader.size();

    }

    @Override
    public View getHeaderView(int position, View convertView,
            ViewGroup parent) {
        TextView holder;
        if (convertView == null) {
            holder = (TextView) inflater.inflate(R.layout.date_header,
                    parent, false);
        } else {
            holder = (TextView) convertView;
        }
        holder.setText(datesHeader.get(position));
        return holder;
    }

    @Override
    public int getNumHeaders() {
        // TODO Auto-generated method stub
        return 0;
    }

}


首先,我遇到的问题是它不对其中任何一个(简单和标头)执行getView。我的下一个想法是如何设置特定图像的标题。我有一个图像网址的数组列表,另一个是标题(月)。请帮助我,因为我已经花了4天了,找不到任何解决方案。

最佳答案

对于网格视图适配器,您的getcount()为零。

关于android - StickyGridHeader示例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16898876/

10-10 08:44