有人可以告诉那条特定行中的错误是什么。
以下是显示的错误消息。
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);
}
}
}
答案 0 :(得分:9)
FirebaseUI的最新版本(3.x)实现了一种初始化FirebaseRecyclerAdapter
的方法,而不是以前的版本。来自using the FirebaseRecyclerAdapter documentation:
首先,通过构建
FirebaseRecyclerOptions
来配置适配器。在 在这种情况下,我们将继续我们的聊天示例:FirebaseRecyclerOptions<Chat> options = new FirebaseRecyclerOptions.Builder<Chat>() .setQuery(query, Chat.class) .build();
接下来创建
FirebaseRecyclerAdapter
对象。你应该已经 有一个ViewHolder
子类用于显示每个项目。
因此,对于您的示例,您需要执行与以下类似的操作:
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。
答案 1 :(得分:2)
您错过了启动活动的方法。
在onStart()
方法中添加:
firebaseRecyclerAdapter.startListening();
答案 2 :(得分:0)
你好你的错误是由于在这个
旁边的这些()中缺少一个参数<image_details, BlogViewHolder>
所以你错过了BlogViewHolder类的另一个参数,所以我将添加这段代码并通过以下注释引用你缺少的参数:
FirebaseRecyclerAdapter<image_details, BlogViewHolder> adapter = new FirebaseRecyclerAdapter<image_details, BlogViewHolder>(
image_details.class,
R.layout.individual_row,
BlogViewHolder.class //see this is missing so you should add it
myRef) {
答案 3 :(得分:0)
这是正确的方法:
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
// ...
}
};
答案 4 :(得分:0)
我有同样的错误,这对我来说非常有效。希望对别人有帮助
<a href="http://www.nameofshop.eu/detail.php?recordID=<?php echo $row_rsDetail['product_id']; ?>" target="_new"><input type="submit" name="goToShop" value="Find in store" /></a>