@Override protected Void doInBackground(Void... params) { String result = null; try { result = run("http://dev.tapptic.com/test/json.php"); } catch (IOException e) { e.printStackTrace(); } if (!TextUtils.isEmpty(result)) { try { JSONArray array = new JSONArray(result); for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); String image = object.getString("image"); String name = object.getString("name"); Contact contact = new Contact(); contact.setImage(image); contact.setName(name); contacts.add(contact); } } catch (JSONException e) { e.printStackTrace(); } } return null; }
@Override public void onClick(View view) { CustomerViewHolder holder = (CustomerViewHolder) view.getTag(); int position = holder.getAdapterPosition(); Contact item = contacts.get(position); Toast.makeText(context, item.getName(), Toast.LENGTH_SHORT).show(); }
@Override public void onBindViewHolder(CustomerViewHolder customerViewHolder, int i) { Contact contact = contacts.get(i); Picasso.with(context) .load(contact.getImage()) .error(R.drawable.ic_launcher) .placeholder(R.drawable.ic_launcher) .into(customerViewHolder.image); customerViewHolder.name.setText(contact.getName()); customerViewHolder.rltItem.setTag(customerViewHolder); customerViewHolder.rltItem.setOnClickListener(onClickListener); }