Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Created November 24, 2009 16:28
Show Gist options
  • Select an option

  • Save shaobin0604/241993 to your computer and use it in GitHub Desktop.

Select an option

Save shaobin0604/241993 to your computer and use it in GitHub Desktop.
class RowAdapter extends CursorAdapter {
private final LayoutInflater mInflater;
public RowAdapter(Context context, Cursor c, boolean autoRequery) {
super(context, c, autoRequery);
mInflater = LayoutInflater.from(context);
}
public RowAdapter(Context context, Cursor c) {
super(context, c);
mInflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tvDate = (TextView) view.findViewById(R.id.tv_date);
TextView tvTime = (TextView) view.findViewById(R.id.tv_time);
TextView tvWeek = (TextView) view.findViewById(R.id.tv_week);
TextView tvVs = (TextView) view.findViewById(R.id.tv_vs);
StringBuilder date = new StringBuilder(cursor.getString(cursor
.getColumnIndex(DatabaseHelper.C_DATE)));
StringBuilder time = new StringBuilder(cursor.getString(cursor
.getColumnIndex(DatabaseHelper.C_TIME)));
String week = cursor.getString(cursor
.getColumnIndex(DatabaseHelper.C_WEEK));
String vs = cursor
.getString(cursor.getColumnIndex(DatabaseHelper.C_VS));
if (DateFormat.format("yyyyMMdd", System.currentTimeMillis())
.toString().equals(date.toString())) {
view.setBackgroundColor(Color.BLUE);
}
tvDate.setText(date.insert(4, '-').insert(7, '-'));
tvTime.setText(time.insert(time.length() - 2, ':'));
tvWeek.setText(week);
tvVs.setText(vs);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = mInflater.inflate(R.layout.list_item, parent, false);
return view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment