private void fillData() { Cursor notesCursor = mDbHelper.fetchAllNotes(); startManagingCursor(notesCursor); CursorAdapter notes; // showing just visible description, or number too? String[] from; String format; if (showNumberToo) { // Create an array to specify the fields we want to display in the list from = new String[] {DbAdapter.KEY_DESC, DbAdapter.KEY_NUMBER}; // put DESC in the first {} and NUMBER in the second {} format = "{} - {}"; } else { // analagous to the above, but only showing the visible description from = new String[] {DbAdapter.KEY_DESC}; format = "{}"; } // if notes = new FormattableCursorAdapter( this, notesCursor, from, format, R.id.text1, R.layout.notes_row, mDbHelper); setListAdapter(notes); }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // its actually the order... Cursor c = mDbHelper.fetchNoteFromOrder(id); String number = c.getString(c.getColumnIndexOrThrow(DbAdapter.KEY_NUMBER)); String recipient = c.getString(c.getColumnIndexOrThrow(DbAdapter.KEY_RECIP)); // send a text to EasyGo sendText(number, recipient); } // onListitemClick
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Cursor c = mDbHelper.fetchNoteFromOrder(info.id); long rowid = c.getLong(c.getColumnIndexOrThrow(DbAdapter.KEY_ROWID)); switch (item.getItemId()) { case DELETE_ID: info = (AdapterContextMenuInfo) item.getMenuInfo(); mDbHelper.deleteNote(rowid); fillData(); return true; case EDIT_ID: Intent i = new Intent(this, EditorActivity.class); i.putExtra(DbAdapter.KEY_ROWID, rowid); startActivityForResult(i, ACTIVITY_EDIT); return true; case TEXT_ID: // c declared above String number = c.getString(c.getColumnIndexOrThrow(DbAdapter.KEY_NUMBER)); String recipient = c.getString(c.getColumnIndexOrThrow(DbAdapter.KEY_RECIP)); sendText(number, recipient); } // switch return super.onContextItemSelected(item); } // onContextItemSelected
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notes_list); mDbHelper = new DbAdapter(this); mDbHelper.open(); fillData(); registerForContextMenu(getListView()); quickTextBox = (EditText) findViewById(R.id.quicktextbox); // sets up alerts alert = new AlertDialog.Builder(this).create(); setUpDragNDrop(); // update preferences getPrefs(); }