[英]Populate RecyclerView using Sugar ORM
This is what I have right now it gets the right number of items but it displays the column name. 这就是我现在所拥有的,它获得了正确数量的项目,但它显示了列名。 Not the individual cell names.
不是单个单元格名称。 For Example I'll have 3 entries in the database(I checked and it worked fine).
例如,我将在数据库中有3个条目(我检查了一下,效果很好)。 Then when I try to populate the
RecyclerView
all I get is 3 entries that say name; 然后,当我尝试填充
RecyclerView
我得到的只是3个说姓名的条目;
My adapter: 我的适配器:
public class RecyclerViewAdapter extends RecyclerView.Adapter{
private List<Session> sessionLists;
private static Context sContext;
public RecyclerViewAdapter(List<Session> sessionLists){
this.sessionLists = sessionLists;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View layoutView = LayoutInflater
.from(viewGroup.getContext())
.inflate(R.layout.item_row, null);
return new MyViewHolder(layoutView);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
Session sessionList = sessionLists.get(position);
MyViewHolder myViewHolder = (MyViewHolder) viewHolder;
}
@Override
public int getItemCount() {
return sessionLists.size();
}
/** This is our ViewHolder class */
public static class MyViewHolder extends RecyclerView.ViewHolder {
public TextView tvSessionName;
public TextView tvSessionDate;
public TextView tvArrowsShot;
public MyViewHolder(View itemView) {
super(itemView); // Must call super() first
tvSessionName = (TextView) itemView.findViewById(R.id.tvSessionName);
tvSessionDate = (TextView) itemView.findViewById(R.id.tvSessionDate);
tvArrowsShot = (TextView) itemView.findViewById(R.id.tvArrowsShot);
}
}
}
This is my Session.java for Sugar ORM
: 这是我的
Sugar ORM
Session.java:
public class Session extends SugarRecord<Session> {
String date, name;
public Session(){
}
public Session(String date, String name){
this.date = date;
this.name = name;
}
public String[] getSession(){
return new String[]{date, name};
}
public String toString(){
return date;
}
}
This is how I am calling it in the main activity: 这是我在主要活动中的调用方式:
List<Session> sessionList = Session.listAll(Session.class);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(sessionList);
recyclerView.setAdapter(adapter);
Well, me not thinking forgot to set the TextViews
. 好吧,我没想到忘记设置
TextViews
。 If you wondering I forgot 如果你想知道我忘了
myViewHolder.tvSessionName.setText(sessionLists.get(position).toString());
inside onBindViewHolder
里面
onBindViewHolder
I believe this is the correct way to do this. 我相信这是正确的方法。 If not people inform me.
如果没有人通知我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.