gpt4 book ai didi

java - FirebaseRecyclerView中的FireBaseRecyclerView无法应用于: (arguments)

转载 作者:行者123 更新时间:2023-11-30 00:17:07 26 4
gpt4 key购买 nike

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

我的 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);
}
}
}

这是显示为错误的内容

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)

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

PS:我正在使用 Fragments That error is shown here

最佳答案

在 Activity 声明下写:-

  private FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter;

然后在 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..

上面的return v;:

     recyclerView.setAdapter(adapter);

使用此方法代替 onBindViewHolder:

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

确保您在模型类 JournalEntry.class 和容器类 JournalHolder.class 中拥有所有正确的方法,并且它的位置和布局正确。

关于java - FirebaseRecyclerView中的FireBaseRecyclerView无法应用于: (arguments),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47061142/

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