1

this is my json

{
contacts: [
{
id: "c200",
name: "Ravi Tamada",
email: "ravi@gmail.com",
address: "xx-xx-xxxx,x - street, x - country",
gender: "male",
image: "http://www.madam.com.tr/wp-content/uploads/2014/06/Tango-Siempre-80x80.jpg",
phone: {
mobile: "+91 0000000000",
home: "00 000000",
office: "00 000000"
}
},

i pars this json and i set these name, email, address, gender items but i can not set image in layout.

and this is my view adapter

  @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            // brand new
            convertView = LayoutInflater.from(mContext).inflate(R.layout.film_list_item, null);
            holder = new ViewHolder();

            holder.nameLabel= (TextView) convertView.findViewById(R.id.nameLabel);
            holder.emailLabel= (TextView) convertView.findViewById(R.id.emailLabel);
            holder.genderLabel= (TextView) convertView.findViewById(R.id.genderLabel);
            holder.addressLabel= (TextView) convertView.findViewById(R.id.addressLabel);
            holder.imageId= (ImageView) convertView.findViewById(R.id.imageId);


            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }

        Film day = mFilmler[position];

        byte[] decodedString = Base64.decode(String.valueOf(holder.imageId), Base64.URL_SAFE);
        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);


        holder.nameLabel.setText(day.getName());
        holder.emailLabel.setText(day.getEmail());
        holder.genderLabel.setText(day.getGender());
        holder.addressLabel.setText(day.getAddress());
        holder.imageId.setImageURI(Uri.parse(day.getImage()));


        return convertView;
    }

    private static class ViewHolder {
        TextView nameLabel; // public by default
        TextView emailLabel;
        TextView genderLabel;
        TextView addressLabel;
        ImageView imageId;
    }

how i can set this image url as an image in my listview ?

Ahmet Yuva
  • 21
  • 5

1 Answers1

0

The fastest way? Use a library like Picasso. It will fetch the image from the URL provided and populate your ImageView. At the moment you're not loading the data. You're just giving it the URL to the data.

An example Adapter that uses Picasso:

https://github.com/androidfu/Now-Playing/blob/master/app/src/main/java/com/androidfu/nowplaying/app/ui/adapters/MovieAdapter.java

The line to add to the dependencies in your app/build.gradle:

compile 'com.squareup.picasso:picasso:2.3.3'

Picasso ...

Picasso.with(getContext())
                    .load(day.getImage())
                    //.placeholder(R.drawable.admit_one)
                    //.error(R.drawable.emoticon_sad)
                    .into(holder.imageId, new Callback() {
                                @Override
                                public void onSuccess() {
                                }

                                @Override
                                public void onError() {
                                }
                            }
                    );
Bill Mote
  • 12,644
  • 7
  • 58
  • 82