【问题标题】:How to retrieve key value to listview from firebase database? [duplicate]如何从firebase数据库中检索listview的键值? [复制]
【发布时间】:2018-07-22 14:43:27
【问题描述】:

我已将日期保存为密钥。现在我想将日期检索到列表视图。我知道如何将子值检索到列表视图,但不确定如何对键值执行相同操作。以下是我正在使用的代码:

databaseReference = FirebaseDatabase.getInstance().getReference().child(savedCollname).
child("Students").child(userId).child("Lectures").child(post_key);

FirebaseListOptions<String> options = new FirebaseListOptions.Builder<String>()
.setLayout(R.layout.subject_list_heading)

.setQuery(databaseReference, String.class)
.build();

adapter = new FirebaseListAdapter<String>(options) {


@Override
protected void populateView(View v, String model, int position) {

TextView subject_name = v.findViewById(R.id.tv_sub_heading);
subject_name.setText(model);



}
};

list_of_date.setAdapter(adapter);

我的应用程序因错误而崩溃:Failed to convert value of type java.util.Hashmap to String

数据库的JSON对象:

{
  "-LHSdSCzD_tZhzqvSOw_" : {
    "17-7-2018" : {
      "Absent" : "0",
      "Present" : "1",
      "Total_Lectures" : "1"
    },
      "18-7-2018" : {
      "Absent" : "0",
      "Present" : "1",
      "Total_Lectures" : "1"
    }
}

我想检索日期,即列表视图的节点。 如果有其他方法请提及。任何帮助表示赞赏。

【问题讨论】:

    标签: android firebase-realtime-database firebaseui


    【解决方案1】:
    @Override
    protected void populateView(View v, String model, int position) {
        adapter.getRef(position).getKey();
        //Use this method to get the key.
    
    }
    

    【讨论】:

    • 应用程序仍然崩溃,出现与上述相同的错误。
    猜你喜欢
    • 2018-12-26
    • 1970-01-01
    • 2018-10-08
    • 2016-11-13
    • 1970-01-01
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多