jeudi 2 avril 2015

Populate a recyclerview with a SQLite database?

I wish to populate my recyclerview with my SQLite database but I am unsure how to do so. I am stuck and unsure how to do so. I believe it has something to do with adapter but again I am not sure.


If you need to see and additional code like my SQLite class or the recyclerview activity please don't hesitate to ask.


Any help would be greatly appreciated.


Here is my adapter:



public class SQLite_RecyclerViewAdapter extends RecyclerView.Adapter<SQLite_RecyclerViewAdapter.VHItem> {
List<SQLite_Information> data = Collections.emptyList();



public SQLite_RecyclerViewAdapter(Sqlite_activity sqlite_activity, List<SQLite_Information> data) {
this.data = data;
}

@Override
public VHItem onCreateViewHolder(ViewGroup parent, int viewType) {
return new VHItem(LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_sqlite_row, parent, false)); }

@Override
public void onBindViewHolder(VHItem holder, int position) {
SQLite_Information sqLite_information = data.get(position);
holder.Score.setText(sqLite_information.mScore);
holder.Date.setText(sqLite_information.mDate);
}

@Override
public int getItemCount() {
return data.size();
}


class VHItem extends RecyclerView.ViewHolder {
TextView Score;
TextView Date;

public VHItem(View itemView) {
super(itemView);
Score = (TextView) itemView.findViewById(R.id.ScoreText);
Date = (TextView) itemView.findViewById(R.id.DateText);
}
}

}

Aucun commentaire:

Enregistrer un commentaire