Skip to content

Instantly share code, notes, and snippets.

Last active February 21, 2016 13:12
Show Gist options
  • Save kundansviet/0227cdd686429a8d001a to your computer and use it in GitHub Desktop.
Save kundansviet/0227cdd686429a8d001a to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
* Created by androidwarriors on 2/18/2016.
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListViewHolder> {
Context context;
List<UserData> dataList = new ArrayList<>();
LayoutInflater inflater;
Listener listener;
public ListAdapter(Context context, List<UserData> dataList1) {
this.context = context;
this.dataList = dataList1;
this.listener= (Listener) context;
inflater = LayoutInflater.from(context);
public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View convertView = inflater.inflate(R.layout.row, parent, false);
ListViewHolder viewHolder = new ListViewHolder(convertView);
return viewHolder;
public void onBindViewHolder(ListViewHolder holder, int position) {
holder.iv_delete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
listener.nameToChnge(dataList.get((Integer) v.getTag()).name);
public int getItemCount() {
return dataList.size();
class ListViewHolder extends RecyclerView.ViewHolder {
TextView tv_name;
ImageView iv_delete;
public ListViewHolder(View itemView) {
tv_name = (TextView) itemView.findViewById(;
iv_delete= (ImageView) itemView.findViewById(;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment