Java 如何获取获取的firebase数据的父值?
在这里,我从firebase数据库获取数据,并在recylerview中设置。 它已成功运行,但我需要新意图的parent值 我使用了这种类型的代码 我需要回收视图中每个绑定laout的密钥。 但问题是当我使用getAdapterPosition(i)时,它返回值,ok。但我需要它的实际价值Java 如何获取获取的firebase数据的父值?,java,android,Java,Android,在这里,我从firebase数据库获取数据,并在recylerview中设置。 它已成功运行,但我需要新意图的parent值 我使用了这种类型的代码 我需要回收视图中每个绑定laout的密钥。 但问题是当我使用getAdapterPosition(i)时,它返回值,ok。但我需要它的实际价值 public class AllPostAdapter extends RecyclerView.Adapter<AllPostAdapter.AllPostViewHolder> {
public class AllPostAdapter extends RecyclerView.Adapter<AllPostAdapter.AllPostViewHolder>
{
}
@NonNull
@Override
public AllPostViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i)
{
View view=LayoutInflater.from(context).inflate(R.layout.all_post_layout,viewGroup,false);
AllPostViewHolder viewHolder=new AllPostViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull AllPostViewHolder allPostViewHolder, int i)
{
//Here i need the parent actual value not like 0,1,2,3...//
holder.name.setText(Post.get(i).getName());
holder.email.setText(Post.get(i).getEmail());
}
@Override
public int getItemCount() {
return postArrayList.size();
}
public类AllPostAdapter扩展了RecyclerView.Adapter
{
}
@非空
@凌驾
public AllPostViewHolder onCreateViewHolder(@NonNull ViewGroup ViewGroup,int i)
{
视图=布局更平坦。从(上下文)。充气(R.layout.all\u post\u布局,视图组,false);
AllPostViewHolder viewHolder=新的AllPostViewHolder(视图);
返回视图持有者;
}
@凌驾
BindViewHolder上的公共无效(@NonNull AllPostViewHolder AllPostViewHolder,int i)
{
//这里我需要的父实际值不象0,1,2,3//
holder.name.setText(Post.get(i.getName());
holder.email.setText(Post.get(i.getEmail());
}
@凌驾
public int getItemCount(){
返回postArrayList.size();
}
假设您的意思是需要获取firebase实时数据库项唯一密钥。首先,从获取代码的地方获取密钥
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
Comment newPost = dataSnapshot.getValue(Post.class);
String postKey = dataSnapshot.getKey();
newPost.setKey(postKey)
}
@Override
public void onBindViewHolder(@NonNull AllPostViewHolder allPostViewHolder, int i)
{
Post post = postArrayList.get(i)
holder.name.setText(post.getName());
holder.email.setText(post.getEmail());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context , YourIntent.class);
intent.putExtra("Key" , post.getKey());
holder.itemView.getContext().startActivity(intent);
}
});
}
然后,在recyclerview适配器中,您可以获取密钥并调用意图,像这样传递该密钥
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
Comment newPost = dataSnapshot.getValue(Post.class);
String postKey = dataSnapshot.getKey();
newPost.setKey(postKey)
}
@Override
public void onBindViewHolder(@NonNull AllPostViewHolder allPostViewHolder, int i)
{
Post post = postArrayList.get(i)
holder.name.setText(post.getName());
holder.email.setText(post.getEmail());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context , YourIntent.class);
intent.putExtra("Key" , post.getKey());
holder.itemView.getContext().startActivity(intent);
}
});
}
您的问题没有提供完整的信息和明确的问题。你能提供更多的细节并清楚地说明你的问题吗?这是一个明确的问题。你没有得到什么内容?