【问题标题】:how to create closed circular Recyclerview with custom Recycler adapter?如何使用自定义 Recycler 适配器创建封闭的循环 Recyclerview?
【发布时间】:2016-10-13 14:00:35
【问题描述】:

这可能是重复的,但仍然没有正确的答案。 我提到了thisthisthis

如链接中所述,我希望实现一个循环的 recyclerview,即

[view 1]-[view 2]....-[view N-1]-[view N]-[view 1].....等等

由于在 recyclerview 中没有获取 View 和获取 Item 的覆盖方法,我 我无法成功。

请帮忙。在此先感谢!

我的回收器适配器代码

public class HorizontalRecyclerAdapter extends RecyclerView.Adapter<HorizontalRecyclerAdapter.ProductViewHolder> {

    List<Product> products;
    private Context mContext;
    ImageLoader imageLoader;


    HorizontalRecyclerAdapter(List<Product> products, Context mContext) {
        this.products = products;
        this.mContext = mContext;

    }

    @Override
    public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.product_layout, parent, false);
        return new ProductViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final ProductViewHolder holder, int position) {

        imageLoader = SingletonRequestQueue.getInstance(mContext).getImageLoader();
        String URL = products.get(position).getProductImageUrl();
        holder.progressBar.setVisibility(View.VISIBLE);
        /* to hide the progress bar after image response */

        imageLoader.get(URL, new ImageLoader.ImageListener() {
            @Override
            public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
                if (response != null) {
                    Bitmap bitmap = response.getBitmap();
                    if (bitmap != null) {
                        holder.progressBar.setVisibility(View.GONE);
                    }
                }
            }
            @Override
            public void onErrorResponse(VolleyError error) {}
        });
        holder.itemImage.setImageUrl(URL, imageLoader);
        holder.itemName.setText(products.get(position).getProductName());
        holder.itemPrice.setText("₹ "+products.get(position).getProductPrice());
        holder.sellerLogo.setImageResource(products.get(position).getProductSellerId());

    }

    @Override
    public int getItemCount() {
        return products.size();
    }

    public static class ProductViewHolder extends RecyclerView.ViewHolder {

        NetworkImageView itemImage;
        NetworkImageView sellerLogo;
        TextView itemName;
        TextView itemPrice;
        ProgressBar progressBar;


        public ProductViewHolder(View itemView) {
            super(itemView);
            itemImage = (NetworkImageView) itemView.findViewById(R.id.product_image);
            sellerLogo = (NetworkImageView) itemView.findViewById(R.id.product_seller);
            itemName = (TextView) itemView.findViewById(R.id.product_name);
            itemPrice = (TextView) itemView.findViewById(R.id.product_price);
            progressBar = (ProgressBar)itemView.findViewById(R.id.network_image_progressbar);


        }
    }
}

【问题讨论】:

    标签: java android android-recyclerview


    【解决方案1】:

    我稍微深入研究了一下,发现了一个可行的解决方案/hack here。我已经对其进行了测试,它运行良好。我正在结束这个问题。谢谢!

    【讨论】:

      【解决方案2】:

      检查我的答案here。我已经尝试过,它适用于回收站视图,并从末端创建无尽的滚动效果。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-30
        • 1970-01-01
        • 2018-06-11
        • 1970-01-01
        • 2017-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多