Приложение падает при скроле ListView
Добавлено: 06 фев 2014, 18:32
Приветствую!
Выводу список контактов в ListView
На эмуляторе 20 записей - скролю - все отлично.
На реальном телефоне записей более 550 - приложение падает, когда скролл доходит до упора вниз. Исключением с телефона пока не обладаю т.к. не удалось подружить устройство с дебаг режимом. Заранее спасибо!
Выводу список контактов в ListView
Код: Выделить всё
Cursor contactCursor = BaseActivity.instance().getContactsCursor();
indexer = new AlphabetIndexer(contactCursor, contactCursor.getColumnIndex(Data.DISPLAY_NAME), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
public static Contact getContact(ContentResolver cr, Cursor cursor, int position) {
try {
cursor.moveToFirst();
boolean success = cursor.move(position);
if (!success)
return null;
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Identity._ID));
String name = getContactDisplayName(cursor);
Uri photo = getContactPictureUri(id);
InputStream input = getContactPictureInputStream(cr, id);
Contact contact;
if (input == null) {
contact = new Contact(id, name);
}
else {
Bitmap bm = null;
try {
bm = BitmapFactory.decodeStream(input);
} catch (OutOfMemoryError oome) {}
contact = new Contact(id, name, photo, bm);
}
return contact;
} catch (Exception e) {
}
return null;
}
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
private Bitmap bitmapUnknown;
private List<Contact> contacts;
private Cursor cursor;
ContactsListAdapter(List<Contact> contactsList, Cursor c) {
contacts = contactsList;
cursor = c;
bitmapUnknown = BitmapFactory.decodeResource(getResources(), R.drawable.unknown_small);
Log.i("cl", "bitmapUnknown: " + bitmapUnknown);
}
public int getCount() {
return cursor.getCount();
}
public Object getItem(int position) {
if (position >= contacts.size()) {
return contacts.get(position);
} else {
return contacts.get(position);
}
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
Contact contact = null;
do {
contact = (Contact) getItem(position);
} while (contact == null);
if (convertView != null) {
view = convertView;
} else {
view = mInflater.inflate(R.layout.contact_cell, parent, false);
}
TextView name = (TextView) view.findViewById(R.id.name);
name.setText(contact.getName());
TextView separator = (TextView) view.findViewById(R.id.separator);
LinearLayout layout = (LinearLayout) view.findViewById(R.id.layout);
if (getPositionForSection(getSectionForPosition(position)) != position) {
separator.setVisibility(View.GONE);
} else {
separator.setVisibility(View.VISIBLE);
separator.setText(String.valueOf(contact.getName().charAt(0)));
}
ImageView icon = (ImageView) view.findViewById(R.id.icon);
if (contact.getPhoto() != null) {
icon.setImageBitmap(contact.getPhoto());
} else if (contact.getPhotoUri() != null) {
icon.setImageURI(contact.getPhotoUri());
} else {
icon.setImageBitmap(bitmapUnknown);
}
return view;
}
@Override
public int getPositionForSection(int section) {
return indexer.getPositionForSection(section);
}
@Override
public int getSectionForPosition(int position) {
return indexer.getSectionForPosition(position);
}
@Override
public Object[] getSections() {
return indexer.getSections();
}
}На реальном телефоне записей более 550 - приложение падает, когда скролл доходит до упора вниз. Исключением с телефона пока не обладаю т.к. не удалось подружить устройство с дебаг режимом. Заранее спасибо!