两个不同的数据库引用合并在单个recyclerView适配器中,显示在不同的列表中,但是怎么可能

时间:2019-04-18 11:18:29

标签: android firebase firebase-realtime-database android-recyclerview

我有一个类,它将显示用户的出勤情况,但是我有一个问题,因为我存储在不同的数据库引用中。我如何调用数据库的两个子级,并根据到目前为止的出勤类型在回收者布局中显示某些信息,但我在下面有此内容,但是它不能正常工作。这里的数据库结构是Structure   活动代码为:

  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();
}

它只显示一个缺席用户列表,但不显示当前用户。我希望它同时显示两个用户

0 个答案:

没有答案