- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将数据从 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)
请帮帮我。我尝试了所有方法,但没有任何效果。或者,如果您有任何建议...提前致谢。
最佳答案
在 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/
我正在寻求实现搜索功能。当它运行时,logcat 告诉我: E/RecyclerView: No adapter attached; skipping layout. 我已经搜索了SO和网络,答案告诉
我收到此错误,但我不知道如何修复它 java.lang.IndexOutOfBoundsException: Index: 2, Size: 2 at java.util.ArrayList.get(
我正在开发一个博客应用程序,我在其中创建了 card_view,其中显示了用户名、个人资料图片、发布时间和其他详细信息。到目前为止,一切都很好,除了一件事时间和日期。现在这是一件需要花费大量时间研究的
OnCreateView 内的代码 contactList = v.findViewById(R.id.contacts_list); contactList.setLayoutMan
我需要显示一个列表(来自 Firebase 实时数据库的数据绑定(bind)到 RecyclerView),该列表位于 root -> History -> UID -> location, date
我需要在 RecyclerView 中添加标题 View ,我使用的适配器来自 Firebase ui。 对于普通的 RecyclerView 适配器,我会简单地处理不同的 View 类型并处理一些计
我是一名优秀的程序员,十分优秀!