gpt4 book ai didi

android - 如何在使用 Firebase UI 在 recyclerView 中显示时从 firebase 数据库中的子项引用父项

转载 作者:搜寻专家 更新时间:2023-11-01 09:29:08 24 4
gpt4 key购买 nike

我目前正在引用 quote_text 子项。这些数据使用 firebase UI 在 recyclerview 中显示。我想获取 quote_text 的父名称。你如何获得 quote_text child 的 parent 姓名。

当用户单击收藏按钮时,我想获取 quote_id 并创建另一个 key 。请帮我。 Screen Shot

这是我的项目代码:

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() 方法访问数据快照。像这样:

@Override
protected void onBindViewHolder(@NonNull QuoteViewHoler holder, int position, @NonNull Quote model) {
this.getSnapshots().getSnapshot(position).getKey();
}

关于android - 如何在使用 Firebase UI 在 recyclerView 中显示时从 firebase 数据库中的子项引用父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48640230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com