public class ContactAdapter extends BaseAdapter { @Override public int getCount() { return data.size(); } @Override public Object getItem(int position) { return data.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { Contact contact = data.get(position); LayoutInflater inflater = (LayoutInflater)context.getLayoutInflater(); View contactView = inflater.inflate(R.layout.contact_view, parent, false); ImageView contactPhotoImageView = (ImageView)contactView.findViewById(R.id.contact_photo_image_view); TextView contactNameTextView = (TextView)contactView.findViewById(R.id.contact_name_text_view); TextView contactTimesContactedTextView = (TextView)contactView.findViewById(R.id.contact_times_contacted_text_view); TextView contactLastTimeContactedTextView = (TextView)contactView.findViewById(R.id.contact_last_time_contacted_text_view); ImageView contactStarredImageView = (ImageView)contactView.findViewById(R.id.contact_starred_image_view); if (getCheckedItemPosition() == position) { contactView.setBackgroundColor(context.getResources().getColor(R.color.light_blue)); } else { contactView.setBackgroundColor(context.getResources().getColor(R.color.light_gray)); } AssetFileDescriptor assetFileDescriptor = null; try { Uri contactPhotoUri = contact.getPhoto(); if (contactPhotoUri == Uri.EMPTY) { contactPhotoImageView.setImageResource(R.drawable.contact_photo); } else { assetFileDescriptor = context.getContentResolver().openAssetFileDescriptor(contactPhotoUri, "r"); FileDescriptor fileDescriptor = assetFileDescriptor.getFileDescriptor(); if (fileDescriptor != null) { contactPhotoImageView.setImageBitmap(BitmapFactory.decodeFileDescriptor(fileDescriptor, null, null)); } } } catch (FileNotFoundException fileNotFoundException) { Log.e(Constants.TAG, "An exception has occurred: "+fileNotFoundException.getMessage()); if (Constants.DEBUG) { fileNotFoundException.printStackTrace(); } } finally { if (assetFileDescriptor != null) { try { assetFileDescriptor.close(); } catch (IOException ioException) { Log.e(Constants.TAG, "An exception has occurred: "+ioException.getMessage()); if (Constants.DEBUG) { ioException.printStackTrace(); } } } } contactNameTextView.setText(contact.getName()); contactTimesContactedTextView.setText(context.getResources().getString(R.string.times_contacted)+" "+contact.getTimesContacted()); long value = contact.getLastTimeContacted(); if (value != 0) { contactLastTimeContactedTextView.setText(context.getResources().getString(R.string.last_time_contacted)+" "+Utilities.displayDateAndTime(value)); } else { contactLastTimeContactedTextView.setText(context.getResources().getString(R.string.last_time_contacted)+" -"); } if (contact.getStarred() == 1) { contactStarredImageView.setImageResource(R.drawable.star_set); } else { contactStarredImageView.setImageResource(R.drawable.star_unset); } return contactView; } }