问题描述
谁能告诉我该特定行中的错误是什么.
Can someone please tell what's the error in that specific line.
这是显示的错误消息.
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);
}
}
}
推荐答案
FirebaseUI 的最新版本 (3.x) 实现了与以前版本不同的 FirebaseRecyclerAdapter
初始化方法.从使用 FirebaseRecyclerAdapter 文档:
The latest version (3.x) of FirebaseUI implements a different method of initializing a FirebaseRecyclerAdapter
than previous versions. From the using the FirebaseRecyclerAdapter documentation:
首先,通过构建 FirebaseRecyclerOptions
来配置适配器.在在这种情况下,我们将继续我们的聊天示例:
FirebaseRecyclerOptions<Chat> options =
new FirebaseRecyclerOptions.Builder<Chat>()
.setQuery(query, Chat.class)
.build();
接下来创建 FirebaseRecyclerAdapter
对象.你应该已经有一个 ViewHolder
子类用于显示每个项目.
Next create the FirebaseRecyclerAdapter
object. You should already have a ViewHolder
subclass for displaying each item.
因此,对于您的示例,您需要执行以下操作:
So, for your example, you'll need to do something similar to:
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 生命周期文档.
Finally, the FirebaseRecyclerAdapter
uses an event listener to monitor changes to the Firebase query. To begin listening for data, call adapter.startListening()
and adapter.stopListening()
to stop the listener. It's recommended to call these in onStart()
and onStop()
respectively. Further details on this are available in the FirebaseRecyclerAdapter lifecycle documentation.
这篇关于firebaserecycleradapter() 不能应用于 FirebaseRecyclerAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!