private void populateList() { Cursor c = mDbAdapter.getContacts(); startManagingCursor(c); // let android handle cursor life ContactsCursorAdapter contacts = new ContactsCursorAdapter(this, c); setListAdapter(contacts); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mApp = (MarvinApplication) getApplication(); mApp.requestPassword(this); setContentView(R.layout.contact_list); mDbAdapter = new MarvinDbAdapter(this); mDbAdapter.open(); populateList(); getListView() .setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Intent intent = new Intent(); intent.setClassName("com.marvinmessaging", "com.marvinmessaging.NewMessage"); intent.putExtra(MarvinDbAdapter.KEY_ID, id); startActivity(intent); } }); getListView() .setOnCreateContextMenuListener( new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { /* MenuInflater inflater = getMenuInflater(); inflater.inflate(R.layout.contact_list_contextmenu, menu); */ menu.setHeaderTitle("Actions:"); menu.add(0, MSG_CONTACT_ITEM, 0, "Message Contact"); menu.add(0, EDIT_CONTACT_ITEM, 0, "Edit Contact"); menu.add(0, DELETE_CONTACT_ITEM, 0, "Delete Contact"); menu.add(0, CANCEL_CONTACT_ITEM, 0, "Cancel"); } }); }
@Override public void onDestroy() { super.onDestroy(); mDbAdapter.close(); }