模型类数据未绑定到视图

时间:2019-05-04 07:48:27

标签: android firebase firebaseui

我正在使用模型类将数据绑定到使用firebaseui的recyclerview中,但是无法正确解析或绑定

  

模型类

public class HistoryModel {

    String  Cost,Date,Dest,From,Time;

    public HistoryModel() {

    }

    public HistoryModel(String cost, String date, String dest, String from, String time) {
        Cost = cost;
        Date = date;
        Dest = dest;
        From = from;
        Time = time;
    }


}

具有Firebase UI的主类

具有FirebaseRecycler Ui的主类,并在oncreateviewHolder和BindviewHolder上实现并查询以跟踪数据更改,但我不知道如何将具有id和childs的firebase数据模型绑定到recyclerview

   query= FirebaseDatabase.getInstance()
            .getReference("TripHistory").child(Userid);



    options= new FirebaseRecyclerOptions.Builder<HistoryModel>()
            .setQuery(query, new SnapshotParser<HistoryModel>() {
                @NonNull
                @Override
                public HistoryModel parseSnapshot(@NonNull DataSnapshot snapshot) {

                    return null;
                }
            })
            .build();


      adapter = new FirebaseRecyclerAdapter<HistoryModel,ViewHolder>(options) {    

        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

            histDesView= LayoutInflater.from(getApplicationContext())
                    .inflate(R.layout.historydesign,viewGroup,false);

            Log.i(TAG,"Creating View Holder");
            return new ViewHolder(histDesView);

        }


        @Override
        protected void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull HistoryModel model) {
            Log.i(TAG,"Binding the data");

            holder.Dest.setText(model.Dest);
            holder.From.setText(model.From);
            holder.Time.setText(model.Time);
            holder.Date.setText(model.Date);
            holder.Cost.setText(model.Cost);

            Log.i(TAG,"Binding Data");

        }
    };

    adapter.startListening();
    adapter.notifyDataSetChanged();
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
    historyRecycler.setLayoutManager(linearLayoutManager);
    historyRecycler.setAdapter(adapter);

Firebase Data Model which i want to parse in recycler view

  

要绑定到Recyclerview Json结构的数据

 "TripHistory" : 
{
    "0RMHQ7TdndX2aOXID89bpbu6Lnm1" :
 {
      "01" : {
        "Cost" : "Rs 150",
        "Date" : "04/05/2019",
        "Dest" : "Islamabad",
        "From" : "Wahcantt",
        "Time" : "12:04"
      },
      "02" : {
        "Cost" : "Rs 50",
        "Date" : "05/5/2019",
        "Dest " : "Rawalpindi",
        "From" : "Islamabad",
        "Time" : "12:00"
      }
    }
  }
}

0 个答案:

没有答案