public class SearchAdapter extends RecyclerView.Adapter {
Context context;
ArrayList<String> studentNameList;
ArrayList<String> studentMatrikList;
ArrayList<String> studentPhoneList;
ArrayList<String> studentAddressList;
ArrayList<String> studentStatusList;
ArrayList<String> studentMailList;
ArrayList<String> studentConList;
ArrayList<String> studentIdList;
class SearchViewHolder extends RecyclerView.ViewHolder{
TextView studentName, studentMatrik, studentPhone, studentAddress, studentStatus, studentMail, studentCon, studentId, Check;
CheckBox checkBox;
Button buttonMap;
DatabaseReference databaseReference;
public SearchViewHolder(View itemView) {
super(itemView);
studentName = (TextView) itemView.findViewById(R.id.studentName);
studentMatrik = (TextView) itemView.findViewById(R.id.studentMatrik);
studentPhone = (TextView) itemView.findViewById(R.id.studentPhone);
studentAddress = (TextView) itemView.findViewById(R.id.studentAddress);
studentStatus = (TextView) itemView.findViewById(R.id.studentStatus);
studentMail = (TextView) itemView.findViewById(R.id.studentMail);
studentCon = (TextView) itemView.findViewById(R.id.studentCon);
studentId = (TextView) itemView.findViewById(R.id.studentId);
checkBox = (CheckBox) itemView.findViewById(R.id.checkBox);
String name = studentName.getText().toString();
if(name.equals("a")){
checkBox.setChecked(true);
}else{
checkBox.setChecked(false);
}
buttonMap = (Button) itemView.findViewById(R.id.buttonMap);
buttonMap.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MapsViewActivity.class);
intent.putExtra("Latitude",studentMail.getText().toString());
intent.putExtra("Longitude",studentCon.getText().toString());
intent.putExtra("Address",studentAddress.getText().toString());
context.startActivity(intent);
}
});
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked) {
String id = studentId.getText().toString();
databaseReference = FirebaseDatabase.getInstance().getReference("student");
String name = "Check";
databaseReference.child(id).child("stat").setValue(name);
notifyDataSetChanged();
} else {
String id = studentId.getText().toString();
databaseReference = FirebaseDatabase.getInstance().getReference("student");
String name = "Not Check";
databaseReference.child(id).child("stat").setValue(name);
notifyDataSetChanged();
}
}
});
}
I've retrieve all the data from firebase to recyclerview textview itemview, when I try if else condition in adapter it compare with textview android:text in xml not the firebase data value, why is this happen??
studentName = (TextView) itemView.findViewById(R.id.studentName);
String name = studentName.getText().toString();
if(name.equals("a")){
checkBox.setChecked(true);
}else{
checkBox.setChecked(false);
}
It compares with the textview android:text Name goes here in xml not the firebase value...
<TextView
android:id="@+id/studentName"
android:layout_width="205dp"
android:layout_height="wrap_content"
android:text="Name goes here"
android:textColor="#212121"
android:textSize="15sp" />
Aucun commentaire:
Enregistrer un commentaire