Skip to content Skip to sidebar Skip to footer

How Can I Put Photos(from Drawable Folder) In A Listview With The Url From A Json File

I'm making an app with data from several people with the names, mobile phone number and photograph. The JSON file is on the assets folder, the photos are on the drawable folder. H

Solution 1:

Well you can set the resource directly from resource like this

intimageResource= getResources().getIdentifier(@drawable/myresource.png, null, getPackageName());

imageview= (ImageView)findViewById(R.id.imageView);
Drawableres= getResources().getDrawable(imageResource);
imageView.setImageDrawable(res);

Bind it to the list on your adapter !

Solution 2:

You use your Adapter for this like this.

LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    View rowView = mInflater.inflate(R.layout.dashboard_adapter, null);
    TextView textView_area = (TextView) rowView
            .findViewById(R.id.textView_area);

    ImageView big = (ImageView) rowView.findViewById(R.id.big);

    try {
    Picasso.with(context).load(dashboard_ArrayList.get(position).getImagepath()).into(big);
    textView_area.setText(dashboard_ArrayList.get(position).getCat_name());

    }catch (Exception e) {
        e.printStackTrace();
    }

big.png is the image in the drawable folder.

Solution 3:

For this either you need to write conditions, which mapping your photo path to drawable resources

OR

Copy those drawable in Internal or External SD card

Post a Comment for "How Can I Put Photos(from Drawable Folder) In A Listview With The Url From A Json File"