如何专门从Firebase检索数据并将其显示在列表视图中?

时间:2019-05-03 21:46:44

标签: java firebase if-statement

我做了一些编码,将播放器的信息存储到Firebase中。下面是我的Firebase数据结构,其中包含一些信息,例如playerName,playerClub。

Firebase Data Structure

我的问题是,我需要做什么,以便我能够检索与所需条件相匹配的球员的信息,就我而言,我想检索所有将显示所有信息的守门员球员是守门员的球员的信息,包括他的名字,俱乐部。

    @Override
protected void onStart()
{
    super.onStart();
    //attaching value event listener
    databasePlayers.addValueEventListener(new ValueEventListener()
    {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot)
        {

            //clearing the previous player list
            players.clear();

            //iterating through all the nodes
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren())
            {
                //getting player
                Player player = postSnapshot.getValue(Player.class);
                if(player.getPlayerPosition().equals("Defender"))
                {
                    //adding player to the list
                    players.add(player);
                }
            }

            //creating adapter
            GKAdminReference playerAdapter = new GKAdminReference(DFSearchList.this, players);
            //attaching adapter to the listview
            LVGKSList.setAdapter(playerAdapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError)
        {

        }
    });
}

0 个答案:

没有答案