我有节点,我正在尝试使节点成为父节点。
我正在尝试获取黑线数据。
MAX(id)
这行代码Query query = FirebaseDatabase.getInstance().getReference(Params.GENRESCOMMENTS).child(video.getGenre())
.child(video.getVideoID());
Log.d(TAG,"Query: " + query.toString());
options = new FirebaseRecyclerOptions.Builder<Comment>().setQuery(query,Comment.class).build();
adapter = new FirebaseRecyclerAdapter<Comment,CommentsSingleVideoView>(options) {
@Override
public CommentsSingleVideoView onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_item,parent,false);
return new CommentsSingleVideoView(view);
}
@Override
protected void onBindViewHolder(CommentsSingleVideoView holder, int position, final Comment model) {
Log.d(TAG,"Model: " + model.toString());
final String videoID = (String) this.getSnapshots().getSnapshot(position).getKey();
Log.d(TAG,"Video ID: " + videoID);
final String userCommentUID = model.getUserCommentUID();
holder.tvUserName.setText(model.getUserName());
holder.tvComment.setText(model.getComment());
holder.tvDate.setText(model.getUploadDate());
仅使我得到红线。
我需要获取黑线数据。
我该怎么办?
答案 0 :(得分:0)
要获取父节点,请在onBindViewHolder
内尝试以下操作:
String videoID = this.getRef(position).getKey();
getRef(position)
将返回引用的源位置,而getKey()
将检索该节点。
firebaseui文档中的代码:
@NonNull
@Override
public DatabaseReference getRef(int position) {
return mSnapshots.getSnapshot(position).getRef();
}