我想获得如下图所示的键值。我正在使用 firebase 回收器适配器来检索来自键的数据,但现在我想获取键值。现在我正在使用的代码仅检索数据 this 。 private void setFirebaseRecyclerAdapterKarangan() { firebaseRecyclerOptionsKarangan = new FirebaseRecyclerOptions.Builder<UserAlphaKaranganClick>() .setQuery(databaseReference.child("userAlphaKaranganClick").child(userUid), UserAlphaKaranganClick.class) .build(); firebaseRecyclerAdapterKarangan = new FirebaseRecyclerAdapter<UserAlphaKaranganClick, UserAlphaActivityLogKaranganViewHolder>(firebaseRecyclerOptionsKarangan) { @Override protected void onBindViewHolder(@NonNull final UserAlphaActivityLogKaranganViewHolder holder, final int position, @NonNull final UserAlphaKaranganClick model) { //We need to convert to become string since it is from long holder.getTextViewClick().setText(String.valueOf(model.getClick())); holder.getTextViewLike().setText(String.valueOf(model.getLike())); } @NonNull @Override public UserAlphaActivityLogKaranganViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.user_alpha_activity_log_karangan_item, viewGroup, false); return new UserAlphaActivityLogKaranganViewHolder(view); } }; //Display LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext()); linearLayoutManager.setStackFromEnd(true); linearLayoutManager.setReverseLayout(true); firebaseRecyclerAdapterKarangan.startListening(); recyclerView2.setAdapter(firebaseRecyclerAdapterKarangan); recyclerView2.setLayoutManager(linearLayoutManager);}爪哇安卓火力基地
1 回答
鸿蒙传说
TA贡献1865条经验 获得超7个赞
在方法内部onBindViewHolder
添加以下内容:
String key = firebaseRecyclerAdapterKarangan.getRef(position).getKey();
getKey()
将检索随机 ID 中此快照的引用。
添加回答
举报
0/150
提交
取消