-
Notifications
You must be signed in to change notification settings - Fork 40
/
VerticalRecyclerViewAdapter.java
86 lines (67 loc) · 2.56 KB
/
VerticalRecyclerViewAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.thedeveloperworldisyours.fullrecycleview.vertical;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.thedeveloperworldisyours.fullrecycleview.R;
import java.util.ArrayList;
/**
* Created by javierg on 25/01/2017.
*/
public class VerticalRecyclerViewAdapter extends RecyclerView
.Adapter<VerticalRecyclerViewAdapter
.DataObjectHolder> {
private ArrayList<VerticalData> mDataset;
private static VerticalRecyclerViewAdapter.MyClickListener sClickListener;
static class DataObjectHolder extends RecyclerView.ViewHolder
implements View
.OnClickListener {
TextView mLabel;
TextView mDateTime;
DataObjectHolder(View itemView) {
super(itemView);
mLabel = (TextView) itemView.findViewById(R.id.vertical_list_item_title);
mDateTime = (TextView) itemView.findViewById(R.id.vertical_list_item_subtitle);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
sClickListener.onItemClick(getAdapterPosition(), v);
}
}
void setOnItemClickListener(VerticalRecyclerViewAdapter.MyClickListener myClickListener) {
this.sClickListener = myClickListener;
}
VerticalRecyclerViewAdapter(ArrayList<VerticalData> myDataset) {
mDataset = myDataset;
}
@Override
public VerticalRecyclerViewAdapter.DataObjectHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.vertical_list_item, parent, false);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
@Override
public void onBindViewHolder(VerticalRecyclerViewAdapter.DataObjectHolder holder, int position) {
holder.mLabel.setText(mDataset.get(position).getmTitle());
holder.mDateTime.setText(mDataset.get(position).getmSubTitle());
}
void addItem(VerticalData dataObj, int index) {
mDataset.add(dataObj);
notifyItemInserted(index);
}
void deleteItem(int index) {
mDataset.remove(index);
notifyItemRemoved(index);
}
@Override
public int getItemCount() {
return mDataset.size();
}
interface MyClickListener {
void onItemClick(int position, View v);
}
}