gpt4 book ai didi

android - firebaserecycleradapter() 不能应用于 FirebaseRecyclerAdapter

转载 作者:行者123 更新时间:2023-11-30 04:58:46 27 4
gpt4 key购买 nike

谁能告诉我那一行的错误是什么。

Here is the image

这是显示的错误消息。

Error Message

package com.example.souravkumar.sqaurewallpapers;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;

/**
* Created by Sourav Kumar on 11/3/2017.
*/

public class popular extends AppCompatActivity {

private RecyclerView recyclerView;
private DatabaseReference myRef;
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
myRef = FirebaseDatabase.getInstance().getReference();
FirebaseRecyclerAdapter<image_details, BlogViewHolder> adapter = new FirebaseRecyclerAdapter<image_details, BlogViewHolder>(
image_details.class,
R.layout.individual_row,

myRef) {
@Override
protected void onBindViewHolder(BlogViewHolder holder, int position, image_details model) {
holder.setDate(model.getDate());
holder.setUrl(model.getUrl());
}

@Override
public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}
};

recyclerView.setAdapter(adapter);

}

public static class BlogViewHolder extends RecyclerView.ViewHolder {
TextView textView;
ImageView imageView;
public BlogViewHolder(View itemView) {
super(itemView);
textView = (TextView)itemView.findViewById(R.id.date);
imageView = (ImageView)itemView.findViewById(R.id.imageView);
}

public void setDate(Long date) {
textView.setText(date.toString());
}

public void setUrl(String url) {
Picasso.with(itemView.getContext())
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView);
}
}
}

Link to the whole code

最佳答案

FirebaseUI 的最新版本 (3.x) 实现了与以前版本不同的初始化 FirebaseRecyclerAdapter 的方法。来自using the FirebaseRecyclerAdapter documentation :

First, configure the adapter by building FirebaseRecyclerOptions. In this case we will continue with our chat example:

 FirebaseRecyclerOptions<Chat> options =
new FirebaseRecyclerOptions.Builder<Chat>()
.setQuery(query, Chat.class)
.build();

Next create the FirebaseRecyclerAdapter object. You should already have a ViewHolder subclass for displaying each item.

因此,对于您的示例,您需要执行类似于以下操作的操作:

FirebaseRecyclerOptions<image_details> options =
new FirebaseRecyclerOptions.Builder<image_details>()
.setQuery(myRef, image_details.class)
.build();

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<image_details, BlogViewHolder>(options) {
@Override
public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.individual_row, parent, false);

return new BlogViewHolder(view);
}

@Override
protected void onBindViewHolder(BlogViewHolder holder, int position, image_details model) {
// Bind the image_details object to the BlogViewHolder
// ...
}
};

最后,FirebaseRecyclerAdapter 使用事件监听器来监视对 Firebase 查询的更改。要开始监听数据,请调用 adapter.startListening()adapter.stopListening() 来停止监听器。建议分别在 onStart()onStop() 中调用它们。有关这方面的更多详细信息,请参阅 FirebaseRecyclerAdapter lifecycle documentation .

关于android - firebaserecycleradapter() 不能应用于 FirebaseRecyclerAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58627792/

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