Tuesday, August 23, 2016

Membuat Recycleview Image Picasso Sederhana

  بِسْمِ اللّهِ الرَّحْمَنِ الرَّحِيْمِ
Kali ini saya akan membahas mengenai bagaimana cara membuat recyleview image dengan menggunakan picasso.

pertama yang dibutuhkan adalah kalian harus menambahkan dependencies ke dalam grandle app.
compile 'com.android.support:recyclerview-v7:23.2.0'compile  
'com.squareup.picasso:picasso:2.5.2'
buat file xml dengan nama row_layout


kemudian pada  main_activity tambahkan


selanjutny pada row_layout tambhakan


selanjutnya buat file java dengan nama DataAdapter
dan tambahkan kode
package com.taufiqhdidayah.recyclerviewgrid;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private ArrayList<AndroidVersion> android;
private Context context;
public DataAdapter(Context context,ArrayList<AndroidVersion> android) {
this.android = android;
this.context = context;
}
@Override public DataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_layout, viewGroup, false);
return new ViewHolder(view);
}
@Override public void onBindViewHolder(DataAdapter.ViewHolder viewHolder, int i) {
viewHolder.tv_android.setText(android.get(i).getAndroid_version_name());
Picasso.with(context).load(android.get(i).getAndroid_image_url()).resize(240, 120).into(viewHolder.img_android);
}
@Override public int getItemCount() {
return android.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView tv_android;
private ImageView img_android;
public ViewHolder(View view) {
super(view);
tv_android = (TextView)view.findViewById(R.id.tv_android);
img_android = (ImageView) view.findViewById(R.id.img_android);
}
}
} 
buat lagi file java dengan nama Propinsi
dan tambahkan kode
package com.taufiqhidayah.recyclerviewgrid;


public class Propinsi {

    private String android_version_name;
    private String android_image_url;

    public String getAndroid_version_name() {
        return android_version_name;
    }

    public void setAndroid_version_name(String android_version_name) {
        this.android_version_name = android_version_name;
    }

    public String getAndroid_image_url() {
        return android_image_url;
    }

    public void setAndroid_image_url(String android_image_url) {
        this.android_image_url = android_image_url;
    }
}

0 komentar:

Post a Comment

Berkomentarlah dengan baik dan bijak..