How do I create a Recycliewiew adapter in Android?

I am using LIB . It works fine, but I cannot load my data into the adapter class. as. If I add some static data to be added, but whenever I try to download from the server that will not be added. finally i am trying with this approach.
But when I find Brandinfo and try to add data that will be wrong if there is no colon, etc. please tell me how can I add data to the adapter to complete this recyclerview. Thank you. My Fragment Class

List<BrandInfo> mContentItems = new ArrayList<BrandInfo>();
pbDialog = new ProgressDialog(getActivity());
    // Showing progress dialog before making http request
    JsonArrayRequest movieReq = new JsonArrayRequest(url,
            new Response.Listener<JSONArray>() {
                public void onResponse(JSONArray response) {
                    Log.d("BrandViewActivity", response.toString());

                    // Parsing json
                    for (int i = 0; i < response.length(); i++) {
                        try {

                            JSONObject obj = response.getJSONObject(i);
                            brandInfo = new BrandInfo();
                            mContentItems.add(new BrandInfo().setBrandname(obj.getString("title")));
                            String title = obj.getString("title");
                            String location = obj.getString("location");
                            String image = obj.getString("image_path");
                            String category = obj.getString("category");

                            Log.d("fffffffffff", mContentItems.toString());
                        } catch (JSONException e) {

            }, new Response.ErrorListener() {
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d("Error aa gai bhaya", "Error: " + error.getMessage());



This is my Brandinfo class:

public class BrandInfo {
private String brandname;
private String brandinfo;
private String address;
private String detail;

public String getBrandname() {
    return brandname;
public void setBrandname(String brandname) {
    this.brandname = brandname;
public String getBrandInfo() {
    return brandinfo;
public void setBrandinfo(String brandinfo) {
    this.brandname = brandinfo;
public String getAddress() {
    return address;
public void setAddress(String address) {
    this.address = address;
public String getDetail() {
    return detail;
public void setSex(String detail) {
    this.detail = detail;



Finally, this is my adapter class:

public class TOAdapter extends RecyclerView.Adapter<TOAdapter.ViewHolder> {

private List<BrandInfo> brandLists = new ArrayList<BrandInfo>();
private ImageLoader imageLoader;

public TOAdapter(List<BrandInfo> brandLists) {
    this.brandLists = brandLists;

// Create new views (invoked by the layout manager)
public TOAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                               int viewType) {
    // create a new view
    View itemLayoutView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.list_item_card_big, null);

    // create ViewHolder

    ViewHolder viewHolder = new ViewHolder(itemLayoutView);
    return viewHolder;

// Replace the contents of a view (invoked by the layout manager)
public void onBindViewHolder(ViewHolder viewHolder, int position) {

    // - get data from your itemsData at this position
    // - replace the contents of the view with that itemsData

    BrandInfo brandList = new BrandInfo();

   imageLoader = AppController.getInstance().getImageLoader();
    if (imageLoader == null)
        imageLoader = AppController.getInstance().getImageLoader();
    viewHolder.thumbNail.setImageUrl(brandList.getBrandname(), imageLoader);


public int getItemCount() {
    String s = String.valueOf(brandLists.size());
    return brandLists.size();

public static class ViewHolder extends RecyclerView.ViewHolder {
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();

    public TextView txtViewTitle;
    final NetworkImageView thumbNail;

    public ViewHolder(View itemLayoutView) {
        txtViewTitle = (TextView) itemLayoutView.findViewById(;

        thumbNail = (NetworkImageView) itemLayoutView




source to share

2 answers

So, I would recommend the following (which I use in my own project):

Create the following TOAdapter method for yourself:

public void refreshRecyclerViewBrands(List<BrandInfo> brandLists) {
    this.brandLists = brandLists;


Then call the following method from which you initialized the recyclerviewadapter and your list:



Basically it is the list you just got from volley and tells recyclerview to use this new list and update recyclerview. This worked for me so, hopefully will work for you.

Another thing I noticed, in yours onBindViewHolder

, you set the following:

BrandInfo brandList = new BrandInfo();


Then you use:



But brandlist.getBrandname is null. Never give the brandlist object any values, rather use the following:

final BrandInfo brandList = brandLists.get(position);


Hope it helps.



you should do this

  JSONObject obj = response.getJSONObject(i);
  brandInfo = new BrandInfo();


then i add my adapter like this Adapter CustomSourcingAdapter = new
      CustomSourcingAdapter (Sourcing_modes.this, publishPlacementList); lists.setAdapter (adapter);

this is my custom Adapter class
    public class CustomSourcingAdapter extends ArrayAdapter<SourcingModel> {

private final Activity context;

private final List<SourcingModel> publishPlacementList;

public CustomSourcingAdapter(Activity context,List<SourcingModel>       
publishPlacementList) {
    // TODO Auto-generated constructor stub

    super(context, R.layout.sorsinglist,publishPlacementList);
    // TODO Auto-generated constructor stub


static class ViewHolder {
    protected TextView placementtitle;
    protected TextView Noofposition;
    protected ImageButton next;
    protected TextView Department;


public View getView(int position,View converview,ViewGroup parent) {
    ViewHolder viewHolder = null;
    if (converview ==null ){
        LayoutInflater inflater=context.getLayoutInflater();
        converview=inflater.inflate(R.layout.sorsinglist, null);
        viewHolder = new ViewHolder();

        viewHolder= (ViewHolder)converview.getTag();


viewHolder.placementtitle.setText (publishPlacementList.get (position) .getPositionName ()); viewHolder.Noofposition.setText (publishPlacementList.get (position) .getNoOfPosition ()); viewHolder.Department.setText (publishPlacementList.get (position) .getName ());; OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            int pos = (Integer) v.getTag();
            long  id = publishPlacementList.get(pos).getId();

            Intent it = new Intent(context, SourcingSecond.class);
            it.putExtra("id", id);


    return converview;





All Articles