-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalytics.java
136 lines (105 loc) · 4.21 KB
/
Analytics.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.example.minesh.cardview;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
package com.example.minesh.cardview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class History_Main_app extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history__main_app);
}
}
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.StudentViewHolder> implements Filterable {
private Context mCtx;
private List<StudentClass> studentList;
private List<StudentClass> tempList;
private OnItemClickListener onItemClickListener;
public interface OnItemClickListener {
void onItemClick(int position);
}
public void setOnItemClickListener(OnItemClickListener listener) {
onItemClickListener = listener;
}
public ListAdapter(Context mCtx, List<StudentClass> facultyList) {
this.mCtx = mCtx;
this.studentList = facultyList;
tempList = facultyList;
}
@NonNull
@Override
public StudentViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.student_list_layout, null);
return new StudentViewHolder(view, onItemClickListener);
}
@Override
public void onBindViewHolder(@NonNull StudentViewHolder facultyViewHolder, int i) {
StudentClass fac = studentList.get(i);
facultyViewHolder.textName.setText("");
facultyViewHolder.textID.setText(fac.gid()+" "+fac.gName());
}
@Override
public int getItemCount() {
return studentList.size();
}
class StudentViewHolder extends RecyclerView.ViewHolder {
TextView textName, textID;
public StudentViewHolder(@NonNull View itemView, final OnItemClickListener listener) {
super(itemView);
textName = itemView.findViewById(R.id.textViewName);
textID = itemView.findViewById(R.id.textViewID);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
listener.onItemClick(position);
}
}
}
});
}
}
public List<StudentClass> currentList() {
return studentList;
}
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
String charString = charSequence.toString();
if (charString.isEmpty()) {
studentList = tempList;
} else {
ArrayList<StudentClass> filteredList = new ArrayList<>();
for (StudentClass fac : tempList) {
if (fac.gName().toLowerCase().contains(charString)) {
filteredList.add(fac);
}
}
studentList = filteredList;
}
FilterResults filterResults = new FilterResults();
filterResults.values = studentList;
return filterResults;
}
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
studentList = (ArrayList<StudentClass>) filterResults.values;
notifyDataSetChanged();
}
};
}
}