daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Nov 22nd, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactViewHolder> {
  2.  
  3.     private Context mContext;
  4.     private List<ContactInfo> contactList;
  5.     private static OnItemClickListener ItemClickListener;
  6.  
  7.     public ContactAdapter(Context context , List<ContactInfo> contactList) {
  8.         this.contactList = contactList;
  9.         this.mContext = context;
  10.     }
  11.  
  12.  
  13.     @Override
  14.     public int getItemCount() {
  15.         return contactList.size();
  16.     }
  17.  
  18.     @Override
  19.     public void onBindViewHolder(ContactViewHolder contactViewHolder, int i) {
  20.        final ContactInfo ci = contactList.get(i);
  21.         contactViewHolder.vName.setText(ci.name);
  22.         contactViewHolder.vSurname.setText(ci.surname);
  23.         contactViewHolder.vEmail.setText(ci.title);
  24.         contactViewHolder.vTitle.setText(ci.email);
  25.  
  26.     }
  27.  
  28.     @Override
  29.     public ContactViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
  30.             View itemView = LayoutInflater.
  31.                     from(viewGroup.getContext()).
  32.                     inflate(R.layout.cardview, viewGroup, false);
  33.  
  34.             return new ContactViewHolder(itemView);
  35.     }
  36.  
  37.  
  38.  
  39.     public static class ContactViewHolder extends RecyclerView.ViewHolder  implements View.OnClickListener, View.OnLongClickListener{
  40.  
  41.         protected TextView vName;
  42.         protected TextView vSurname;
  43.         protected TextView vEmail;
  44.         protected TextView vTitle;
  45.         private OnItemClickListener clickListener;
  46.  
  47.         public ContactViewHolder(View v) {
  48.             super(v);
  49.             vName =  (TextView) v.findViewById(R.id.txtName);
  50.             vSurname = (TextView)  v.findViewById(R.id.txtSurname);
  51.             vEmail = (TextView)  v.findViewById(R.id.txtEmail);
  52.             vTitle = (TextView) v.findViewById(R.id.title);
  53.  
  54.             v.setTag(v);
  55.             v.setOnClickListener(this);
  56.             v.setOnLongClickListener(this);
  57.         }
  58.  
  59.         public void setClickListener(OnItemClickListener itemClickListener) {
  60.             this.clickListener = itemClickListener;
  61.         }
  62.         @Override
  63.         public void onClick(View view) {
  64.             clickListener.onClick(view, getLayoutPosition(),false);
  65.         }
  66.  
  67.         @Override
  68.         public boolean onLongClick(View view) {
  69.             clickListener.onClick(view, getLayoutPosition() , true);
  70.             return true;
  71.         }
  72.     }
  73.  
  74.  
  75.  
  76.     public interface OnItemClickListener {
  77.         void onClick(View view, int layoutPosition, boolean b);
  78.     }
  79.  
  80.  
  81.     public void SetOnItemClickListener(final OnItemClickListener mItemClickListener) {
  82.         this.ItemClickListener = mItemClickListener;
  83.     }
  84. }
  85.    
  86. final ContactAdapter ca = new ContactAdapter(getApplicationContext(),createList(30));
  87.  
  88.         recList.setAdapter(ca);
  89.  
  90.         ca.SetOnItemClickListener(new ContactAdapter.OnItemClickListener() {
  91.             @Override
  92.             public void onClick(View view, int layoutPosition, boolean b) {
  93.  
  94.                 Intent intent = new Intent("com.example.as.a.aa_Detail");
  95.                 startActivity(intent);
  96.             }
  97.         });
  98.     }
  99.    
  100. public static class ContactViewHolder extends RecyclerView.ViewHolder  implements View.OnClickListener, View.OnLongClickListener
  101. {
  102.     protected TextView vName;
  103.     protected TextView vSurname;
  104.     protected TextView vEmail;
  105.     protected TextView vTitle;
  106.  
  107.     public ContactViewHolder(View v) {
  108.         super(v);
  109.         vName =  (TextView) v.findViewById(R.id.txtName);
  110.         vSurname = (TextView)  v.findViewById(R.id.txtSurname);
  111.         vEmail = (TextView)  v.findViewById(R.id.txtEmail);
  112.         vTitle = (TextView) v.findViewById(R.id.title);
  113.  
  114.         v.setTag(v);
  115.         v.setOnClickListener(this);
  116.         v.setOnLongClickListener(this);
  117.     }
  118.  
  119.  
  120.     @Override
  121.     public void onClick(View view) {
  122.         ItemClickListener.onClick(view, getAdapterPosition(),false);
  123.     }
  124.  
  125.     @Override
  126.     public boolean onLongClick(View view) {
  127.         ItemClickListener.onClick(view, getAdapterPosition(), true);
  128.         return true;
  129.     }
  130. }
  131.    
  132. ca.SetOnItemClickListener(new ContactAdapter.OnItemClickListener() {
  133.         @Override
  134.         public void onClick(View view, int layoutPosition, boolean b) {
  135.  
  136.             Intent intent = new Intent("com.example.as.a.aa_Detail");
  137.  
  138.             if (intent.resolveActivity(getPackageManager()) != null) {
  139.                 startActivity(intent);
  140.             }
  141.         }
  142.     });
RAW Paste Data
Top