【发布时间】:2022-01-16 13:47:04
【问题描述】:
我很难从 firestore 的数据库中获取价值。
这是我的数据库的图片:
我要做的是从“添加帖子”文档中获取两个字段作为字符串形式,以将其传递到不同的 XML textView 以获取位置和描述。现在,当我运行它时,我的文本有些乱七八糟。
我想弹出标题位置,即“伊利诺伊州芝加哥”。我该怎么做?
这是我的活动:
package com.example.groupproject
import android.content.ContentValues.TAG
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
class InspectPostActivity : AppCompatActivity() {
private lateinit var locationTextView: TextView
private lateinit var reference: DatabaseReference
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_inspect_post)
// Linking all of the elements to their views
locationTextView = findViewById(R.id.locationView)
reference = FirebaseDatabase.getInstance().reference.child("Chicago, Illinois").child("locationTitle")
// Sets the text to the database location
locationTextView.text = reference.toString()
}
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore