@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); Contact contact = ((ContactAdapter) getListAdapter()).getItem(info.position); switch (item.getItemId()) { case R.id.profile: Intent profileIntent = new Intent(getBaseContext(), ContactViewActivity.class); profileIntent.putExtra("ContactID", contact.getId()); startActivity(profileIntent); return true; case R.id.edit: Intent editIntent = new Intent(getBaseContext(), ContactEditActivity.class); editIntent.putExtra("ContactID", contact.getId()); startActivity(editIntent); return true; case R.id.delete: // TODO Maybe a confirmation??? ContactRepositoryInterface datasource = ContactRepositoryFactory.getInstance().getContactRepository(this, this); this.contact_adapter.remove(contact); datasource.open(); datasource.delete(contact); datasource.close(); refreshList(); return true; default: return super.onContextItemSelected(item); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View item = inflater.inflate(R.layout.contact_list_item, parent, false); Contact contact = getItem(position); ((TextView) item.findViewById(R.id.item_name)).setText(contact.getName()); ((TextView) item.findViewById(R.id.item_title)).setText(contact.getTitle()); // Check if we have gravatar on disk String filename = contact.getId() + "-gravatar.jpg"; try { File imgFile = getFileStreamPath(filename); if (imgFile.exists()) { ImageView iv = (ImageView) item.findViewById(R.id.item_profile_image); Bitmap gravatar = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); iv.setImageBitmap(gravatar); } } catch (Exception e) { Log.e("gravatar", e.getMessage()); } return item; }