FirebaseUI RecyclerView不在更改查询中显示

时间:2019-07-10 16:20:24

标签: android android-recyclerview firebaseui

我正在尝试在回收站视图中包含Reports并有2个按钮public reportmy report。每当单击我的报告时,它只会显示基于当前登录用户的报告,就像单击公共报告一样,它会显示所有报告。到目前为止,我设法将数据填充到“回收者”视图中,但是,每当我尝试单击其中一个按钮时,它都不会显示任何内容,就好像删除了“回收者”视图一样。

适配器没有任何问题,也许有一种“重置”我不知道的适配器的方法。

任何帮助将不胜感激。

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home);

    //For Recycler View
    recyclerView = findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    publicReport();

    everyone = findViewById(R.id.publicReport);
    mine = findViewById(R.id.myReport);

    everyone.setOnClickListener(view -> {
        publicReport();
    });

    mine.setOnClickListener(view ->{
        currentUserReport();
    });
}

private void publicReport(){
    Query query = reportRef.orderBy("date",Query.Direction.DESCENDING);
    FirestoreRecyclerOptions<Report> options  = new FirestoreRecyclerOptions.Builder<Report>()
            .setQuery(query,Report.class)
            .build();

    reportAdapter = new ReportAdapter(options);
    recyclerView.setAdapter(reportAdapter);
    reportAdapter.notifyDataSetChanged();
}


private void currentUserReport(){
    Query query = reportRef.whereEqualTo("reportedByUserID",user.getUid()).orderBy("date",Query.Direction.DESCENDING);
    FirestoreRecyclerOptions<Report> options  = new FirestoreRecyclerOptions.Builder<Report>()
            .setQuery(query,Report.class)
            .build();

    reportAdapter = new ReportAdapter(options);
    recyclerView.setAdapter(reportAdapter);
    reportAdapter.notifyDataSetChanged();
}

ReportAdapter

public class ReportAdapter extends FirestoreRecyclerAdapter<Report, ReportAdapter.ReportHolder> {

    public ReportAdapter(@NonNull FirestoreRecyclerOptions<Report> options) {
        super(options);

    }

    @Override
    protected void onBindViewHolder(@NonNull ReportHolder holder, int i, @NonNull Report report) {
        String seriousLvl = "";

        holder.txtTitle.setText(report.getReportType());
        holder.txtDescription.setText(report.getDescription());
        holder.txtDate.setText(report.getDate());
        holder.txtReportedBy.setText(report.getReportedBy());

        seriousLvl = report.getSeriousness();

        if (seriousLvl.equals("Low")) {
            holder.seriousness.setCardBackgroundColor(Color.parseColor("#77dd77"));
        } else if (seriousLvl.equals("Medium")) {
            holder.seriousness.setCardBackgroundColor(Color.parseColor("#fcfc49"));
        } else if (seriousLvl.equals("High")) {
            holder.seriousness.setCardBackgroundColor(Color.parseColor("#fd8383"));
        }
    }



    @NonNull
    @Override
    public ReportHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.report_item,parent,false);
        return new ReportHolder(v);
    }

    class ReportHolder extends RecyclerView.ViewHolder{

        TextView txtTitle, txtDescription, txtDate, txtReportedBy;
        CardView seriousness;

        public ReportHolder(@NonNull View itemView) {
            super(itemView);
            seriousness = itemView.findViewById(R.id.seriousness);
            txtTitle = itemView.findViewById(R.id.text_view_title);
            txtDescription = itemView.findViewById(R.id.text_view_description);
            txtDate = itemView.findViewById(R.id.text_view_date);
            txtReportedBy = itemView.findViewById(R.id.text_view_report_by);
        }
    }
}

0 个答案:

没有答案