У меня есть класс, который будет отображать посещаемость пользователя, но у меня есть проблема, потому что я храню в другой базе данных ссылки. Как мне вызвать обоих дочерних элементов базы данных и отобразить определенную информацию в макете утилизатора в зависимости от типа посещаемости, пока у меня есть это ниже, но это не работает должным образом. Вот структура базы данных Структура
Код активности:
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int size = (int) dataSnapshot.getChildrenCount();
tc.setText("PRESENT :" +size);
list = new ArrayList<>();
list1=new ArrayList<AttendenceList>();
// list2 = new ArrayList<>();
if(dataSnapshot.exists()) {
// StringBuffer stringbuffer = new StringBuffer();
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
// Intent abintent=getIntent();
EmployeeInformation userdetails = dataSnapshot1.getValue(EmployeeInformation.class);
String naame = userdetails.getNaame();
String employeeno = userdetails.getEmployeeno();
String locationla = userdetails.getLocationla();
String locationlo = userdetails.getLocationlo();
String time = userdetails.getTime();
String report = userdetails.getReport();
String captureimage = userdetails.getCaptureImageUrl();
String totalMember = userdetails.getTeamMember();
String timeTaken = userdetails.getTimeCompletion();
String locationaddress = userdetails.getLocationName();
String membername = userdetails.getMemberName();
String locationimage = userdetails.getLocationPic();
String day=userdetails.getDay();
AttendenceList listdata = new AttendenceList(naame, locationla, locationlo, time, report, employeeno, captureimage, timeTaken, locationimage, totalMember, membername, locationaddress ,day);
list.add(listdata);
}
recycler = new FullAttendenceList(FullAttendenceDetailList.this, list,list2);
RecyclerView.LayoutManager layoutmanager = new LinearLayoutManager(FullAttendenceDetailList.this);
// (LinearLayoutManager) layoutmanager).setOrientation(RecyclerView.VERTICAL);
Precyclerview.setLayoutManager(layoutmanager);
Precyclerview.setItemAnimator(new DefaultItemAnimator());
Precyclerview.setAdapter(recycler);
recycler.notifyDataSetChanged();
pd.dismiss();
}else
{
pd.dismiss();
Toast.makeText(FullAttendenceDetailList.this, "No one mark their attendence 1", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
startActivity(new Intent(FullAttendenceDetailList.this, NetworkSlow.class));
Toast.makeText(FullAttendenceDetailList.this, "Network problem check it", Toast.LENGTH_SHORT).show();
pd.dismiss();
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
ref2.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int size = (int) dataSnapshot.getChildrenCount();
tc1.setText("ABSENT :" + size);
list2 = new ArrayList<>();
if (dataSnapshot.exists()) {
// StringBuffer stringbuffer = new StringBuffer();
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
EmployeeInformation userdetails = dataSnapshot1.getValue(EmployeeInformation.class);
String naame = userdetails.getNaame();
String employeeno = userdetails.getEmployeeno();
String locationla = userdetails.getLocationla();
String locationlo = userdetails.getLocationlo();
String time = userdetails.getTime();
String report = userdetails.getReport();
String captureimage = userdetails.getCaptureImageUrl();
String totalMember ="-"; //userdetails.getTeamMember();
String timeTaken = "-";//userdetails.getTimeCompletion();
String locationaddress ="-";// userdetails.getLocationName();
String membername ="-";// userdetails.getMemberName();
String locationimage ="-";// userdetails.getLocationPic();
String day="-";//userdetails.getDay();
AttendenceList listdata2 = new AttendenceList(naame, locationla, locationlo, time, report, employeeno, captureimage, timeTaken, locationimage, totalMember, membername, locationaddress ,day);
list2.add(listdata2);
// list1.add(list,list2);
}
recycler = new FullAttendenceList(FullAttendenceDetailList.this,list ,list2);
RecyclerView.LayoutManager layoutmanager = new LinearLayoutManager(FullAttendenceDetailList.this);
//(LinearLayoutManager) layoutmanager).setOrientation(RecyclerView.VERTICAL);
Precyclerview.setLayoutManager(layoutmanager);
Precyclerview.setItemAnimator(new DefaultItemAnimator());
Precyclerview.setAdapter(recycler);
recycler.notifyDataSetChanged();
pd.dismiss();
}else
{
pd.dismiss();
Toast.makeText(FullAttendenceDetailList.this, "No one mark their attendence 2", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
startActivity(new Intent(FullAttendenceDetailList.this, NetworkSlow.class));
Toast.makeText(FullAttendenceDetailList.this, "Network problem check it", Toast.LENGTH_SHORT).show();
pd.dismiss();
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
Теперь код класса адаптера:
public class FullAttendenceList extends RecyclerView.Adapter<FullAttendenceList.MyHolder>{
List<AttendenceList> attendencelistdata;
List<AttendenceList> attendencelistdata2;
Context context;
public FullAttendenceList(Context context){
this.context = context;
}
public FullAttendenceList(Context context,List<AttendenceList> attendencelistdata ,List<AttendenceList> attendencelistdata2) {
this.context = context;
this.attendencelistdata = attendencelistdata;
this.attendencelistdata2 = attendencelistdata2;
}
@Override
public FullAttendenceList.MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fullattendance_list, parent, false);
FullAttendenceList.MyHolder myHolder = new FullAttendenceList.MyHolder(view);
return myHolder;
}
public void onBindViewHolder(FullAttendenceList.MyHolder holder, int position) {
AttendenceList data = attendencelistdata.get(position);
holder.vnaame.setText(data.getNaame());
holder.vemployeeno.setText(data.getEmployeeno());
holder.vtime.setText(data.getTime());
holder.vlocationla.setText(data.getLocationla());
holder.vlocationlo.setText(data.getLocationlo());
holder.vreport.setText(data.getReport());
holder.address.setText(data.getLocationName());
holder.memberName.setText(data.getMemberName());
holder.totalMember.setText(data.getTeamMember());
holder.completionTime.setText(data.getTimeCompletion());
holder.vday.setText(data.getDay());
if(holder.vday.getText().equals("-")){
holder.vstatus.setText("Absent");
holder.vstatus.setBackgroundColor(Color.RED);
}else{
holder.vstatus.setText("Present");
}
Picasso.with(context).load(data.getCaptureImageUrl()).placeholder(R.drawable.button_profile_logo).into(holder.Pik);
Picasso.with(context).load(data.getLocationPic()).placeholder(R.drawable.button_profile_logo).into(holder.locationPik);
AttendenceList data2 = attendencelistdata2.get(position);
holder.vnaame.setText(data2.getNaame());
holder.vemployeeno.setText(data2.getEmployeeno());
holder.vtime.setText(data2.getTime());
holder.vlocationla.setText(data2.getLocationla());
holder.vlocationlo.setText(data2.getLocationlo());
holder.vreport.setText(data2.getReport());
holder.address.setText(data2.getLocationName());
holder.memberName.setText(data2.getMemberName());
holder.totalMember.setText(data2.getTeamMember());
holder.completionTime.setText(data2.getTimeCompletion());
holder.vday.setText(data2.getDay());
if(holder.vday.getText().equals("-")){
holder.vstatus.setText("Absent");
holder.vstatus.setBackgroundColor(Color.RED);
}else{
holder.vstatus.setText("Present");
}
Picasso.with(context).load(data2.getCaptureImageUrl()).placeholder(R.drawable.button_profile_logo).into(holder.Pik);
Picasso.with(context).load(data2.getLocationPic()).placeholder(R.drawable.button_profile_logo).into(holder.locationPik);
holder.presentRelative.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context = v.getContext();
if (!holder.vday.getText().equals("-")) {
Intent i = new Intent(context, PresentReportingActivity.class);
i.putExtra("Employeeno", data.getEmployeeno());
i.putExtra("Naame", data.getNaame());
i.putExtra("Report", data.getReport());
i.putExtra("Time", data.getTime());
i.putExtra("Locationla", data.getLocationla());
i.putExtra("Locationlo", data.getLocationlo());
i.putExtra("CaptureImage", data.getCaptureImageUrl());
i.putExtra("CaptureLocation", data.getLocationPic());
i.putExtra("TotalMember", data.getTeamMember());
i.putExtra("MemberName", data.getMemberName());
i.putExtra("CompletionTime", data.getTimeCompletion());
i.putExtra("Address", data.getLocationName());
i.putExtra("Day", data.getDay());
// i.putExtra("Date",data.get);
context.startActivity(i);
}else{
Intent i = new Intent(context, AbsentReportingActivity.class);
i.putExtra("Employeeno", data2.getEmployeeno());
i.putExtra("Naame", data2.getNaame());
i.putExtra("Report", data2.getReport());
i.putExtra("Time", data.getTime());
i.putExtra("Locationla", data2.getLocationla());
i.putExtra("Locationlo", data2.getLocationlo());
i.putExtra("CaptureImage", data2.getCaptureImageUrl());
context.startActivity(i);
}
}
});
}
@Override
public int getItemCount() {
return (attendencelistdata2.size() );// attendencelistdata2.size();
}
Показывает только один список отсутствующего пользователя, но не показывает текущего пользователя. Я хочу, чтобы он показывал их обоих