使用FirebaseUI从Firebase数据库读取数据到Recycleview
来源:爱站网时间:2021-09-16编辑:网友分享
如何从firebase数据库读取计数器,这是结构:在此处输入图像描述
问题描述
如何从firebase数据库中读取计数器,这是结构:enter image description here
思路:
设备和计数器类
public class Counters implements Serializable {
private String CounterName;
private String CounterNumber;
public Counters (){
}
public Counters(String CounterNumber,String CounterName){
this.CounterNumber=CounterNumber;
this.CounterName=CounterName;
}
public String getCounterName() {
return CounterName;
}
public void setCounterName(String counterName) {
this.CounterName = counterName;
}
public String getCounterNumber() {
return CounterNumber;
}
public void setCounterNumber(String counterNumber) {
this.CounterNumber = counterNumber;
}
}
public class Device {
private String title;
private Map CounterNumber;
private Counters counters;
public void setCounter(Map CounterNumber){
this.CounterNumber=CounterNumber;
}
public Map getCounter(){
return CounterNumber;
}
public Counters getCounters(){
return counters;
}
public void setCounters(Counters counters){
this.counters=counters;
}
public Device(){
}
public Device(String title){
this.title=title;
}
public String getTitle(){
return title;
}
public void setTitle(String title){
this.title=title;
}
}
这是我的查询
private void displayDevices(){
options=
new FirebaseRecyclerOptions.Builder()
.setQuery(databaseReference.child("devices").orderByChild("user_id").equalTo(userid),Device.class).build();
adapter=
new FirebaseRecyclerAdapter(options) {
@Override
protected void onBindViewHolder(@NonNull MyRecyclerViewHolder holder, int position, @NonNull Device model) {
holder.txt_title.setText(model.getTitle());
//holder.txt_counter.setText(model.getCounters().getCounterNumber());
counters.add(model.getCounters().getCounterNumber());
Log.e(TAG,counters.toString());
上一篇:将.Net解密转换为Java