Jumat, 24 Februari 2017

Android Working With Volley and RecyclerView

Android Working With Volley and RecyclerView


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation test link ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate another link velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make link again with longer anchor text a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with test link the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English.

Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical test link here too Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of “de Finibus Bonorum et Malorum” (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, “Lorem ipsum dolor sit amet..”, comes from a line in section 1.10.32.


1. Berikut contoh codingan di MainActivity
package com.zarslamgants25.updatesport;

import android.content.Context;
import android.content.Intent;
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.RelativeLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;

/** * Created by WIN10 on 21/02/2017. */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{

    Context context;
    ArrayList<HashMap<String, String>> listData;

    public MyAdapter(Context context, ArrayList<HashMap<String, String>> listData) {
        this.context = context;
        this.listData = listData;
    }

    @Override    public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, null);
        return new ViewHolder(view);
    }

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

        holder.tvheading.setText(listData.get(position).get("id"));
        holder.tvdesc.setText(listData.get(position).get("judul"));
        final String id_articel = listData.get(position).get("id");

        Picasso.with(context)
                .load(listData.get(position).get("gambar"))
                .placeholder(R.mipmap.ic_launcher)
                .into(holder.imageView);

        holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Intent kirimKeDetail = new Intent(view.getContext(), DetailArtikelActivity.class);
                kirimKeDetail.putExtra("id_artikel", id_articel);
                view.getContext().startActivity(kirimKeDetail);
            }
        });

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tvheading;
        public TextView tvdesc;
        public ImageView imageView;
        public RelativeLayout relativeLayout;

        public ViewHolder(View itemView) {
            super(itemView);

            tvheading = (TextView) itemView.findViewById(R.id.textViewHeading);
            tvdesc = (TextView) itemView.findViewById(R.id.textViewDesc);
            imageView = (ImageView) itemView.findViewById(R.id.imgIcon);
            relativeLayout = (RelativeLayout) itemView.findViewById(R.id.relativeLayout);

        }
    }


//===============================================TANPA HASHMAP============================================================//    private List<ListItem> listItems;//    private Context context;////        public MyAdapter(List<ListItem> listItems, Context context) {//        this.listItems = listItems;//        this.context = context;//    }////    @Override//    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {//        View v = LayoutInflater.from(parent.getContext())//                .inflate(R.layout.list_item, parent, false);//        return new ViewHolder(v);//    }////    @Override//    public void onBindViewHolder(ViewHolder holder, int position) {//        ListItem listItem = listItems.get(position);////        holder.tvheading.setText(listItem.getHead());//        holder.tvdesc.setText(listItem.getDesc());////        Picasso.with(context)//                .load(listItem.getImageUrl())//                .into(holder.imageView);////    }////    @Override//    public int getItemCount() {//        return listItems.size();//    }////    public class ViewHolder extends RecyclerView.ViewHolder {////        public TextView tvheading;//        public TextView tvdesc;//        public ImageView imageView;////        public ViewHolder(View itemView) {//            super(itemView);////            tvheading = (TextView) itemView.findViewById(R.id.textViewHeading);//            tvdesc = (TextView) itemView.findViewById(R.id.textViewDesc);//            imageView = (ImageView) itemView.findViewById(R.id.imgIcon);//        }//    }//===============================================TANPA HASHMAP============================================================}

0 komentar:

Posting Komentar