Created
July 17, 2016 22:19
-
-
Save BracketCove/3aa5dd42c848091af14afc6c42647bbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TodoAdapter extends RecyclerView.Adapter<TodoAdapter.CustomViewHolder> { | |
private LayoutInflater inflater; | |
private List<Todo> listData; | |
private ItemClickCallback itemClickCallback; | |
public TodoAdapter (List<Todo> listData, Context c){ | |
inflater = LayoutInflater.from(c); | |
this.listData = listData; | |
} | |
public interface ItemClickCallback { | |
void onItemClick(int p); | |
} | |
public void setItemClickCallback(final ItemClickCallback itemClickCallback) { | |
this.itemClickCallback = itemClickCallback; | |
} | |
@Override | |
public TodoAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view = inflater.inflate(R.layout.item_todo, parent, false); | |
return new CustomViewHolder(view); | |
} | |
@Override | |
public void onBindViewHolder(CustomViewHolder holder, int position) { | |
Todo todo = listData.get(position); | |
holder.todoContent.setText(todo.getTodoContent()); | |
} | |
@Override | |
public int getItemCount() { | |
return 0; | |
} | |
public void setListData(ArrayList<Todo> todoList) { | |
this.listData.clear(); | |
this.listData.addAll(todoList); | |
} | |
class CustomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | |
View container; | |
TextView todoContent; | |
public CustomViewHolder(View itemView) { | |
super(itemView); | |
todoContent = (TextView) itemView.findViewById(R.id.lbl_todo_content); | |
container = itemView.findViewById(R.id.cont_todo_root); | |
container.setOnClickListener(this); | |
} | |
@Override | |
public void onClick(View v) { | |
itemClickCallback.onItemClick(getAdapterPosition()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment