[英]How can I getRef() inside a RecyclerView adapter?
This is the code I tried: 这是我尝试的代码:
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
ChatMessage msg = mMessagesList.get(position);
holder.messageTextView.setText(msg.getMessage());
String key = getRef(position).getKey();
holder.layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
But the getRef()
is red and doesn't work. 但是
getRef()
是红色的,不能正常工作。 I think it should be inside a populateViewHolder
and I don't know how to create one. 我认为它应该在
populateViewHolder
内部,但我不知道如何创建它。
From the documentation it looks like method doesn't accept parameters. 从文档看来,方法不接受参数。
getRef()
getRef()
Used to obtain a reference to the source location for this snapshot.
用于获取对该快照的源位置的引用。
you can use below code in onBindViewHolder()
您可以在
onBindViewHolder()
使用以下代码
String _key=mMessagesList.get(position).getKey();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.