How To Display the Local image(drawable image file) to cardview via json. I wan,t to load image in offline rather then using picasso library : ## How To Display the Local image(drawable image file) to cardview via json. I wan,t to load image in offline rather then using picasso library


----------


 ##


i'm using tab layout And my Frament.java 

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(
                R.layout.fragment, container, false);
        return rootView;

        
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        final ArrayList<Website> babyList = Website.getbabyFromFile("baby&kids.json", getActivity());
        adapter = new WebsiteAdapter(this, babyList);
        recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new GridLayoutManager(getActivity(),2));
        recyclerView.setAdapter(adapter);
    }



My Website.java is


    private String url;
    public String imageUrl;

    public Website() {
    }

    public Website(String url)  {
        this.url = url;

    }

    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public static ArrayList<Website> getbabyFromFile(String filename, Context context) {
        final ArrayList<Website> babyList = new ArrayList<>();

        try {
            // Load data
            String jsonString = loadJsonFromAsset("baby&kids.json", context);
            JSONObject json = new JSONObject(jsonString);
            JSONArray baby = json.getJSONArray("baby&kids");

            // Get Website objects from data
            for(int i = 0; i < baby.length(); i++){
                Website recipe = new Website();

                recipe.setUrl(baby.getJSONObject(i).getString("url"));

                babyList.add(recipe);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return babyList;

    }
    private static String loadJsonFromAsset(String filename, Context context) {
        String json = null;

        try {
            InputStream is = context.getAssets().open(filename);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        }
        catch (java.io.IOException ex) {
            ex.printStackTrace();
            return null;
        }

        return json;
    }



And this is my WebsitAdapter.java




    private Fragment mContext;
    // private LayoutInflater mInflater;
    private ArrayList<Website> mDataSource;
    OnItemClickListener mItemClickListener;


    public  class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        //each data item is just a string in this case

        public TextView url;
        public ImageView thumbnailImageView;
        public ViewHolder(View v) {
            super(v);

            url = (TextView) v.findViewById(R.id.websitename_id);
            thumbnailImageView = (ImageView) v.findViewById(R.id.website_image_id);

            v.setOnClickListener(this);
        }
        @Override
        public void onClick(View view) {


            Intent detailIntent = new Intent(view.getContext(), Webview.class);
            detailIntent.putExtra("url", url.getText().toString());

            mContext.startActivity(detailIntent);

        }





    }
    public interface OnItemClickListener{
        public void onItemClick(View view, int Position);
    }

    public void SetOnItemClickListner(final OnItemClickListener mItemClickListener){
        this.mItemClickListener = mItemClickListener;
    }
    public WebsiteAdapter(Fragment context, ArrayList<Website> items) {
        mContext = context;
        mDataSource = items;
        // mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.cardview_item_website, parent, false);

        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(WebsiteAdapter.ViewHolder holder, int position) {

        // - get element from arraylist at this position
        // - replace the contents of the view with that element

        Website website = mDataSource.get(position);

        holder.url.setText(website.getUrl());
        //Picasso.with(mContext).load(website.imageUrl).placeholder(R.mipmap.ic_launcher).into(holder.thumbnailImageView);

    }

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


And My output is

  [1]: https://i.stack.imgur.com/LVrf6.png**Please give me a solution that if theres is any possible ways to display images that is stored on drawable folder**