Permalink
Browse files

Done T07.04-UpdateTheAdapter

  • Loading branch information...
GinaHsu committed Sep 27, 2017
1 parent 7e2da25 commit c7d4fe52063bd1820a72708bf0db8d5bd2a7af9a
@@ -15,17 +15,18 @@
private Context mContext;
// TODO (1) Replace the mCount with a Cursor field called mCursor
private int mCount;
//private int mCount;
private Cursor mCursor;
/**
* Constructor using the context and the db cursor
* @param context the calling context/activity
*/
// TODO (2) Modify the constructor to accept a cursor rather than an integer
public GuestListAdapter(Context context, int count) {
public GuestListAdapter(Context context, Cursor cursor) {
this.mContext = context;
// TODO (3) Set the local mCursor to be equal to cursor
mCount = count;
this.mCursor = cursor;
}
@Override
@@ -39,20 +40,25 @@ public GuestViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@Override
public void onBindViewHolder(GuestViewHolder holder, int position) {
// TODO (5) Move the cursor to the passed in position, return if moveToPosition returns false
if (!mCursor.moveToPosition(position))
return;
// TODO (6) Call getString on the cursor to get the guest's name
String name = mCursor.getString(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME));
// TODO (7) Call getInt on the cursor to get the party size
int partySize = mCursor.getInt(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE));
// TODO (8) Set the holder's nameTextView text to the guest's name
holder.nameTextView.setText(name);
// TODO (9) Set the holder's partySizeTextView text to the party size
holder.partySizeTextView.setText(String.valueOf(partySize));
}
@Override
public int getItemCount() {
// TODO (4) Update the getItemCount to return the getCount of mCursor
return mCount;
return mCursor.getCount();
}
@@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
// TODO (10) Pass the entire cursor to the adapter rather than just the count
// Create an adapter for that cursor to display the data
mAdapter = new GuestListAdapter(this, cursor.getCount());
mAdapter = new GuestListAdapter(this, cursor);
// Link the adapter to the RecyclerView
waitlistRecyclerView.setAdapter(mAdapter);
@@ -41,6 +41,11 @@ public static void insertFakeData(SQLiteDatabase db){
cv.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 45);
list.add(cv);
cv = new ContentValues();
cv.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "Gina");
cv.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 77);
list.add(cv);
//insert all guests in one transaction
try
{

0 comments on commit c7d4fe5

Please sign in to comment.