FirebaseRecyclerView中的FireBaseRecyclerView无法应用于:(参数) [英] FireBaseRecyclerView in FirebaseRecyclerView can not be applied to : (arguments)

查看:164
本文介绍了FirebaseRecyclerView中的FireBaseRecyclerView无法应用于:(参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Firebase检索数据到Recyclerview。我已经实现了所有其他的步骤,但是现在我在最后阶段出现错误,当我实现适配器(FirebaseRecyclerAdapter)时。

My Fragment

  public class Journal extends Fragment {

RecyclerView recyclerView;
DatabaseReference myref;
@Override
public view onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState){
View v = inflater.inflate(R.layout.activity_journal,container,false);
myref = FirebaseDatabase.getInstance()。getReference(/ Journal);
recyclerView =(RecyclerView)v.findViewById(R.id.journal_rv);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(新的LinearLayoutManager(getContext()));
FirebaseRecyclerAdapter< JournalEntry,JournalHolder> adapter = new FirebaseRecyclerAdapter< JournalEntry,JournalHolder>(
JournalEntry.class,
R.layout.journal_list_item,
JournalHolder.class,
myref){
@Override
protected void onBindViewHolder(JournalHolder holder,int position,JournalEntry model){
holder.setTitle(model.getEvent_title());
holder.setContent(model.getEvent_content());
holder.setSchool(model.getSchool_name());
holder.setDate(model.getDate());
holder.setStudents(model.getNumber_of_students());
holder.setSchoolIv(model.getImg_url());
}

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

return v;

public static class JournalHolder extends RecyclerView.ViewHolder {
TextView Jtitle,Jcontent,Jschool,Jstudents,jdate;
ImageView schoolIV;
public JournalHolder(查看itemView){
super(itemView);
Jtitle =(TextView)itemView.findViewById(R.id.journal_title);
Jcontent =(TextView)itemView.findViewById(R.id.event_content);
Jschool =(TextView)itemView.findViewById(R.id.journal_school);
Jstudents =(TextView)itemView.findViewById(R.id.journal_students);
jdate =(TextView)itemView.findViewById(R.id.journal_dates);
schoolIV =(ImageView)itemView.findViewById(R.id.journal_image);






$ b public void setTitle(String title){
Jtitle.setText(title );
}

public void setContent(String content){
Jcontent.setText(content);


public void setSchool(String school){
Jschool.setText(school);
}

public void setDate(String date){
jdate.setText(date);
}

public void setStudents(String students){
Jstudents.setText(students);

$ b $ public void setSchoolIv(String schoolIv){
Picasso.with(itemView.getContext())
.load(schoolIv)
.into (schoolIV);





这是显示的内容错误

  FirebaseRecyclerView中的FireBaseRecyclerView无法应用于:
JournalEntry.class(java ... consti.last。 database.JournalEntry>)

R.layout.journal_list_item(int)
BlogViewHolder.class(java ... consti.last.Journal.BlogViewHolder>)
myref(com。 ..firebase.database.DatabaseReference)

请帮助我。我尝试了所有的方法,但没有任何工作。
或者如果您有任何建议,请提前致谢。



PS:我使用碎片

解决方案

在Activity声明下写: -

  private FirebaseRecyclerAdapter< JournalEntry,JournalHolder>适配器; 

然后在onCreateView()中:

<$ p (
JournalEntry.class,
R.layout.journal_list_item,
JournalHolder.class,
myref ){//确定这些类和参数是正确的。

上面的 return v;

  recyclerView.setAdapter(adapter); 

使用此方法代替onBindViewHolder:

  @Override 
protected void populateViewHolder(JournalHolder holder,JournalEntry model,int position){

确保在模型类 JournalEntry.class 和持有者类 JournalHolder.class ,并确定其正确的位置和正确的布局。


I'm trying to retrieve data from Firebase to Recyclerview. I've already implement all other steps but now i'm getting error at the last stage when i'm implementing the adapter(FirebaseRecyclerAdapter).

My Fragment

public class Journal extends Fragment {

RecyclerView recyclerView;
DatabaseReference myref;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_journal,container,false);
    myref= FirebaseDatabase.getInstance().getReference("/Journal");
    recyclerView = (RecyclerView) v.findViewById(R.id.journal_rv);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
            JournalEntry.class,
            R.layout.journal_list_item,
            JournalHolder.class,
            myref) {
        @Override
        protected void onBindViewHolder(JournalHolder holder, int position, JournalEntry model) {
            holder.setTitle(model.getEvent_title());
            holder.setContent(model.getEvent_content());
            holder.setSchool(model.getSchool_name());
            holder.setDate(model.getDate());
            holder.setStudents(model.getNumber_of_students());
            holder.setSchoolIv(model.getImg_url());
        }

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

return  v;
}
public static class JournalHolder extends RecyclerView.ViewHolder{
    TextView Jtitle , Jcontent,Jschool,Jstudents,jdate;
    ImageView schoolIV;
    public JournalHolder(View itemView) {
        super(itemView);
        Jtitle =(TextView)itemView.findViewById(R.id.journal_title);
        Jcontent =(TextView)itemView.findViewById(R.id.event_content);
        Jschool =(TextView)itemView.findViewById(R.id.journal_school);
        Jstudents =(TextView)itemView.findViewById(R.id.journal_students);
        jdate =  (TextView)itemView.findViewById(R.id.journal_dates) ;
        schoolIV = (ImageView)itemView.findViewById(R.id.journal_image);





    }

    public void setTitle(String title) {
        Jtitle.setText(title);
    }

    public void setContent(String content) {
        Jcontent.setText(content);
    }

    public void setSchool(String school) {
        Jschool.setText(school);
    }

    public void setDate(String date) {
        jdate.setText(date);
    }

    public void setStudents(String students) {
        Jstudents.setText(students);
    }

    public void setSchoolIv(String schoolIv) {
        Picasso.with(itemView.getContext())
                .load(schoolIv)
                .into(schoolIV);
    }
}
}

This is what is shown as error

FireBaseRecyclerView in FirebaseRecyclerView can not be applied to :
 JournalEntry.class  (java...consti.last.database.JournalEntry>)

R.layout.journal_list_item  (int)
BlogViewHolder.class  (java...consti.last.Journal.BlogViewHolder>)
myref  (com...firebase.database.DatabaseReference)

Please help me. I tried all the methods but nothing works. Or if you have any advice...thank you in advance.

PS : I'm using Fragments

解决方案

under Activity declaration write:-

  private FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter;

then inside onCreateView():

adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
        JournalEntry.class,
        R.layout.journal_list_item,
        JournalHolder.class,
        myref) {   //be sure that these classes and parameters are correct..

above return v;:

     recyclerView.setAdapter(adapter);

Use this method instead of onBindViewHolder:

 @Override
        protected void populateViewHolder(JournalHolder holder,JournalEntry model, int position) {

Be sure you have all the correct methods in the model class JournalEntry.class and holder class JournalHolder.class and that its the right location and right layout.

这篇关于FirebaseRecyclerView中的FireBaseRecyclerView无法应用于:(参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆