Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create closed circular Recyclerview with custom Recycler adapter?

this might be a possible duplicate , but proper answer is still not available. I referred to this and this and this

As stated in the links I wish to implement a recyclerview which is circular ie

[view 1]-[view 2]....-[view N-1]-[view N]-[view 1].....and so on

Since there are no override methods to get View and get Item in recyclerview , I am unable to succeed.

please help.Thanks in Advance!

my recycler adapter code

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


        }
    }
}
like image 937
Vedant Aggrawal Avatar asked Jun 13 '16 08:06

Vedant Aggrawal


People also ask

Is there an addHeaderView equivalent for RecyclerView?

addHeaderView() but you can achieve this by adding a type to your adapter for header. everything seems to be OK and it should work, but however make the recycler view MATCH_PARENT see if anything changes. also if its possible make the recycler view the root of that layout (its good for performance).

Which method must be overridden to implement a RecyclerView adapter?

Override onBindViewHolder instead if Adapter can handle efficient partial bind. The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. The position of the item within the adapter's data set.


1 Answers

I looked in a little deep and found a working solution/hack here.I have tested it and it works well.I am closing this question. thanks!

like image 50
Vedant Aggrawal Avatar answered Oct 23 '22 04:10

Vedant Aggrawal