如何在Recyclerview中显示Firebase中的数据?

时间:2019-05-22 14:10:06

标签: android firebase firebase-realtime-database android-recyclerview

我开发了一个聊天应用程序。我尝试在recyclerview中从firebase数据库中获取数据,但是什么也没显示。我究竟做错了什么? 这是主要活动:

sToolbar = findViewById(R.id.sToolbar);
searchView = findViewById(R.id.SearchView);
recyclerView = findViewById(R.id.sRecyclerView);   
sBnv = findViewById(R.id.sBnv);

searchAdapter = new SearchAdapter(arrayList, getApplicationContext()); 
arrayList = new ArrayList<>();
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(getApplicationContext());
ref = FirebaseDatabase.getInstance().getReference().child("users");

options  = new FirebaseRecyclerOptions.Builder<User>()
        .setQuery(ref, User.class)
            .build();
adapter = new FirebaseRecyclerAdapter<User, UsernameViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull UsernameViewHolder holder, int position, @NonNull User model) {
            holder.t1.setText(model.getUsername());
        }

        @NonNull
        @Override
        public UsernameViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.search_user_item, parent, false);
            return new UsernameViewHolder(view);
        }
    };


    recyclerView.setLayoutManager(llm);
    adapter.startListening();
    recyclerView.setAdapter(adapter);

0 个答案:

没有答案