Пример #1
0
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Task task = mAdapter.getItem(position);
    CheckedTextView taskDescription = (CheckedTextView) view.findViewById(R.id.task_description);

    task.setCompleted(!task.isCompleted());

    if (task.isCompleted()) {
      taskDescription.setPaintFlags(taskDescription.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
      taskDescription.setChecked(true);
    } else {
      taskDescription.setPaintFlags(
          taskDescription.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
      taskDescription.setChecked(false);
    }

    task.saveEventually();
  }
Пример #2
0
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
   super.onListItemClick(l, v, position, id);
   Log.i(LOG_TAG, id + " is clicked at position " + position);
   if (v instanceof CheckedTextView) {
     // doing asynchronous view changes, because the cursor still has old data while the database
     // and the view are changed
     // because we force refresh on every resume, the synchronization after we leave the Activity
     // is taken care of
     CheckedTextView ctv = (CheckedTextView) v;
     // this check view at the certain position, rather than the item, hence the asynchrony
     ctv.setChecked(!ctv.isChecked());
     mAdapter.flipCheckedStatus(id, mNoteId, ctv.isChecked());
     ctv.setPaintFlags(
         ctv.isChecked()
             ? ctv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG
             : ctv.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
     ((HoloNoteCursorAdapter) this.getListAdapter()).getCursor().requery();
   }
 }