Код: Выделить всё
class Adapter extends SimpleCursorAdapter {
private final String LOG_TAG = "myLogs";
Context ctx;
Cursor cursor;
LayoutInflater lInflater;
@SuppressWarnings("deprecation")
public Adapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
ctx = context;
cursor = c;
lInflater = (LayoutInflater) ctx.getSystemService(LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//View v = super.getView(position, convertView, parent);
View v = convertView;
if (v == null) v = lInflater.inflate(R.layout.item, parent, false);
long id = getItemId(position);
v.setTag(id);
final int rowId = cursor.getInt(cursor.getColumnIndex(DB.ALARMCLOCK_ID));
ToggleButton toggle = (ToggleButton) v.findViewById(R.id.toggle);
toggle.setOnCheckedChangeListener(listener);
toggle.setTag(rowId);
toggle.setFocusable(false);
toggle.setFocusableInTouchMode(false);
((TextView) v.findViewById(R.id.text)).setText(db.getHourById(rowId) + ":" + db.getMinuteById(rowId));
return v;
}
OnCheckedChangeListener listener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
db.switchOfAlarm((Integer) buttonView.getTag(), isChecked);
//
setAlarm(getBaseContext());
c.requery();
}
};
}
Я знаю, что с БД нужно работать с CursorLoader.