本文介绍了在Firebase UI中显示在recyclerView中时,如何在Firebase数据库中从子级引用父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在引用quote_text子级.这些数据使用firebase
UI显示在recyclerview
中.我想获取quote_text的父名称.您如何获得quote_text子级的父级名称.
I am currently referencing to the quote_text child. These data are showing in recyclerview
using firebase
UI. I want to get parent name of quote_text. How do you get parent name of quote_text child.
当用户单击收藏夹"按钮时,我想获取quote_id并想创建另一个密钥.请帮我.
When user clicks favorite button then I want to get the quote_id and want to create another key. Please help me.
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Quotes, QuoteHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull QuoteHolder holder, int position, @NonNull Quotes model) {
Log.i("KK", "onBindViewHolder" + model.getQuote_text());
Log.i("KK", "onBindViewHolder AUTHER" + model.getAuther());
//Setting Quotes
holder.setQuote(model.getQuote_text());
//Setting Likes Count
holder.setLikesCount(model.getLikes_count());
}
@Override
public QuoteHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.quote_single_layout, parent, false);
Log.i("KK", "Inflate" + view);
return new QuoteHolder(view);
}
};
Log.i("KK", "Adapter" + firebaseRecyclerAdapter);
mRecylerViewQuote.setAdapter(firebaseRecyclerAdapter);
}
@Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
firebaseRecyclerAdapter.stopListening();
}
public class QuoteHolder extends RecyclerView.ViewHolder{
View view;
//Two share and favorite image buttons
private ImageButton mShareButton;
private ImageButton mFavoriteButton;
//String
String quoteText;
public QuoteHolder(View itemView) {
super(itemView);
view = itemView;
//initialization
mShareButton = view.findViewById(R.id.share_button);
mFavoriteButton = view.findViewById(R.id.favorite_button);
//Click event Handling
mShareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(view.getContext(), "Share Button Clicked", Toast.LENGTH_SHORT).show();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, quoteText);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share Using:"));
}
});
mFavoriteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(view.getContext(), "Favorite Button Clicked", Toast.LENGTH_SHORT).show();
setFavoriteQuote()//Here I want to get parent name of
//quote_text......................
}
});
}
public void setQuote(String quote_text) {
quoteText = quote_text;
TextView mQuoteText = view.findViewById(R.id.quote_text);
mQuoteText.setText("\"" + quote_text + "\"");
if (mQuoteProgress.isShowing())
mQuoteProgress.dismiss();
}
public void setLikesCount(int likes_count) {
TextView mLikesCountText = view.findViewById(R.id.likes_count_text);
Log.i("Count", String.valueOf(likes_count));
mLikesCountText.setText(String.valueOf(likes_count) + " Likes");
if (mQuoteProgress.isShowing())
mQuoteProgress.dismiss();
}
}
推荐答案
您可以使用适配器内部的getSnapshots()
方法访问数据快照.像这样:
You can access the data snapshots by using the getSnapshots()
method inside your adapter. Like this:
@Override
protected void onBindViewHolder(@NonNull QuoteViewHoler holder, int position, @NonNull Quote model) {
this.getSnapshots().getSnapshot(position).getKey();
}
这篇关于在Firebase UI中显示在recyclerView中时,如何在Firebase数据库中从子级引用父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!