Firebase查询获取随机数据 [英] Firebase Query get random data

查看:60
本文介绍了Firebase查询获取随机数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下代码从firebase中获取用户列表;

I can get my user list from firebase with this code;

Query query = FirebaseDatabase.getInstance().getReference().child("Users");

FirebaseRecyclerOptions<User> options = new FirebaseRecyclerOptions.Builder<User>().setQuery(query.orderByChild("name"), User.class).build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<User, UserHolder>(options)
{
    @Override
    protected void onBindViewHolder(final UserHolder holder, int position, User model) {
        final String userid = getRef(position).getKey();
        holder.setHolder(userid);
    }

    @Override
    public UserHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user, parent, false);
        return new UserHolder(UsersActivity.this, view, getApplicationContext());
    }
};
recyclerView.setAdapter(adapter);

我想随机列出我的用户.

I want to list my users randomly.

我该怎么做?

谢谢.

推荐答案

FirebaseUI中的适配器将按从数据库中来的顺序显示项目.它不具有对客户端中的项目重新排序的内置支持.

The adapters in FirebaseUI will show the items in the order in which they come from the database. It does not have any built in support for re-ordering the items in the client.

我在这里想到的最可能的解决方案是编写自己的适配器.

The most likely solution I can think of here is to write your own adapter.

这篇关于Firebase查询获取随机数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆