-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimpleRecyclerviewAdapter.java
101 lines (73 loc) · 2.82 KB
/
SimpleRecyclerviewAdapter.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package your-packagename-here;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import java.util.ArrayList;
import static android.support.v7.widget.RecyclerView.ViewHolder;
public class SimpleRecyclerviewAdapter extends RecyclerView.Adapter<SimpleRecyclerviewAdapter.MyViewHolder> {
private int selectedPosition = 0;
private ArrayList<YourModelClass> dataList;
private ArrayList<Integer> selectCheck;
Context context;
public SimpleRecyclerviewAdapter(Context context, ArrayList<YourModelClass> dataList, ArrayList<Integer> selectCheck) {
this.dataList = dataList;
this.selectCheck = selectCheck;
this.context = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.your_layout, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
final YourModelClass data = dataList.get(position);
if (selectCheck.get(position) == 1) {
holder.checkBox.setChecked(true);
} else {
holder.checkBox.setChecked(false);
}
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for(int k=0; k<selectCheck.size(); k++) {
if(k==position) {
selectCheck.set(k,1);
} else {
selectCheck.set(k,0);
}
}
notifyDataSetChanged();
}
});
holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked==true){
//Do whatever you want to do with selected value
}
}
});
}
@Override
public int getItemCount() {
return pricingList.size();
}
public class MyViewHolder extends ViewHolder {
CheckBox checkBox;
public MyViewHolder(View itemView) {
super(itemView);
checkBox = (CheckBox) itemView.findViewById(R.id.checkBox);
}
}
}