Firebase Data Filter(Kotlin)

Asked

Viewed 42 times

0

Speak for yourself Blz? I’m a beginner in Kotlin and Firebase!

I’m trying to do a search on firebase in a collection that has user task data, I wanted to filter by ID, follow example:

Banco firebase

My search at the moment is like this:

mDatabase.child("TAREFAS_USUARIOS").child(userid)

but that way it won’t and I can’t find another way on the net

Code:

class FrontPage: AppCompatActivity() {

    lateinit var mRecyclerView : RecyclerView
    lateinit var mDatabase : DatabaseReference

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_front_page)

        mRecyclerView = findViewById(R.id.recycler_view)

        mRecyclerView.setHasFixedSize(true)
        mRecyclerView.layoutManager = LinearLayoutManager(this)
        var uid: FirebaseAuth = FirebaseAuth.getInstance()

        mDatabase = FirebaseDatabase.getInstance().reference

        criarNovaTarefa.setOnClickListener {
            startActivity(Intent(this, criar_tarefas::class.java))
            finish()
        }

        logRecyclerView()

    }

    private fun logRecyclerView() {

        var uid: FirebaseAuth = FirebaseAuth.getInstance()
        var userid: String
        userid = uid.uid.toString().trim()


        var FirebaseRecyclerAdapter =  object : FirebaseRecyclerAdapter<tasks_base,userViewHolder>(
            tasks_base::class.java,
            R.layout.list_view_task,
            userViewHolder::class.java,
            mDatabase.child("TAREFAS_USUARIOS").child(userid)

       ){
           override fun populateViewHolder(viewHolder: userViewHolder, model: tasks_base, position: Int) {

               viewHolder.itemView.task_title_view.text = model.task_name
               viewHolder.itemView.task_description_view.text = model.task_description
               viewHolder.itemView.task_type_view.text = model.task_type
               viewHolder.itemView.view_task_fim.text = model.finish
               viewHolder.itemView.view_task_inicio.text = model.init
           }

       }
        mRecyclerView.adapter = FirebaseRecyclerAdapter
    }

}
  • Share the part of the code where you receive the object and try to access it, and explain better what the problem is. It’s hard to help with such a general question

  • Hi Rafael! Follow the code

  • Please, edit your question and put the code there :)

  • Thanks Rafael, I’m new here tb kkkk was bad

1 answer

0


Guys I got!

It is more related to data structuring than to the "query" itself. I swapped the user ID that was once a key value for the identifier of that collection, IE, the user will have his ID and within his ID will have several other Ids that refer to his activities.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.