Any ideas guys?)
# android
m
Any ideas guys?)
stackoverflow 1
e
can you also add your databaseReference creation?
m
For example i can easily call my fun
addTarget()
from this file. And add target. Here is gist: https://gist.github.com/mnewlive/a6a1d4fe1e28920da34c7bc12133fdee
Problem with query I can't get data for
-LmfEVnx-y7c3oh8_U9F
e
it looks like it has a ‘-’ in front of it.
would it be the problem?
a naive attempt
m
the problem is how to call the
-LmfEVnx-y7c3oh8_U9F
For example if i change my chain on smth like this:
Copy code
databaseReference?.child("targets")?.child("users")
            ?.child(uid)?.child("targets")
and after this a log the data:
Copy code
val data = dataSnapshot.value as? HashMap<String, String>?
                Log.d("some", "dataSnap: $data")
i get next:
Copy code
dataSnap: {-LmfOGKjqy-OC4HzxBHF={name=ggg, description=bhhh, guid=-LmfOGKiiQAIcIIWQh8i}, -LmfOLEMiZrgw2m4GgLd={name=hhh, description=nnnj, guid=-LmfOLELLWTos6SXQxIv}, -LmfX6dkBtZzSKbTbnLO={name=щщщщ, description=щщщщ, guid=-LmfX6djA3iflD3yQytN}}
resolved:
Copy code
private fun fetchTarget(guid: String) {
        val targetsRef = databaseReference!!.child("targets").child("users").child(uid.toString()).child("targets")
        val query = targetsRef.orderByChild("guid").equalTo(guid)
        val valueEventListener = object : ValueEventListener {
            override fun onDataChange(dataSnapshot: DataSnapshot) {
                for (targetSnapshot in dataSnapshot.children) {
                    val target = targetSnapshot.getValue(Target::class.java)

                    val name = target?.name ?: ""
                    val description = target?.description ?: ""

                    if (name.isEmpty()) Log.d("some", "nameIsEmpty")
                    else updateViewsContent(name = name, description = description)
                }
            }
            override fun onCancelled(databaseError: DatabaseError) {
                Log.d("some", databaseError.message)
            }
        }
        query.addListenerForSingleValueEvent(valueEventListener)
    }