Android 字母索引器不使用自定义ListView

Android 字母索引器不使用自定义ListView,android,listview,indexing,customization,Android,Listview,Indexing,Customization,我使用字母索引器、节索引器、自定义游标或适配器来定制ListView。下面是相同的代码。但我无法在滚动列表时看到字母表。我还尝试了以下链接 我遗漏了什么吗?您需要将android:fastScrollEnabled=“true”添加到布局xml的列表视图中。您需要将android:fastScrollEnabled=“true”添加到布局xml的列表视图中。对于OP来说可能太晚了,但其他在这里遇到同样问题的人可能会受益 在我的例子中,字母索引器在某些情况下是“随机”存在的,而在其他情况下不在同一

我使用字母索引器、节索引器、自定义游标或适配器来定制ListView。下面是相同的代码。但我无法在滚动列表时看到字母表。我还尝试了以下链接


我遗漏了什么吗?

您需要将android:fastScrollEnabled=“true”添加到布局xml的列表视图中。

您需要将android:fastScrollEnabled=“true”添加到布局xml的列表视图中。

对于OP来说可能太晚了,但其他在这里遇到同样问题的人可能会受益

在我的例子中,字母索引器在某些情况下是“随机”存在的,而在其他情况下不在同一屏幕上

结果表明,如果列表不是很长,快速滚动,因此字母索引器将被挂起。确切的行为可以在类中找到,该类是
AbsListView
的助手类。这里有一段代码决定“列表是否很长”


MIN_PAGES
的定义值为4。如果您的列表项计数至少不是子项计数(可见行)的4倍,则快速滚动器将不会显示字母索引器。

对于OP来说可能太晚了,但是其他在这里遇到相同问题的人可能会受益

在我的例子中,字母索引器在某些情况下是“随机”存在的,而在其他情况下不在同一屏幕上

结果表明,如果列表不是很长,快速滚动,因此字母索引器将被挂起。确切的行为可以在类中找到,该类是
AbsListView
的助手类。这里有一段代码决定“列表是否很长”


MIN_PAGES
的定义值为4。如果列表项计数不超过4倍,则子项计数(可见行)快速滚动器将不会显示字母索引器。

我在这里做类似的事情@Nik在这里也一样。。你在上面找到什么了吗?因为我的搜索已经结束,但没有成功..你试过吗?我在这里做类似的事情@Nik这里也一样。。你在上面找到什么了吗?因为我的搜索已经结束,但没有成功。你试过这个吗?
public class ContactListCustomCursorAdapter extends CursorAdapter implements
    SectionIndexer {

private LayoutInflater inflater;
private CursorsForContacts cursorsForContacts;
private AlphabetIndexer alphabetIndexer;

public ContactListCustomCursorAdapter(Context context, Cursor cursor) {
    super(context, cursor, true);
    inflater = LayoutInflater.from(context);
    cursorsForContacts = new CursorsForContacts(context);
    alphabetIndexer = new AlphabetIndexer(
            cursor,
            cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME),
            " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    //alphabetIndexer.setCursor(cursor);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {

    String contactId = setContactName(view, cursor);
    setContactPhoneNumbers(view, contactId);
    setContactEmails(view, contactId);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final View view = inflater.inflate(R.layout.custom_contact_list_item,
            parent, false);

    return view;
}

private String setContactName(View view, Cursor cursor) {
    int username = cursor
            .getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
    TextView userName = (TextView) view.findViewById(R.id.userName);
    userName.setText(cursor.getString(username));

    return cursor.getString(cursor
            .getColumnIndex(ContactsContract.Contacts._ID));

}

private void setContactPhoneNumbers(View view, String contactId) {
    Cursor phoneCursor = cursorsForContacts.getPhoneNumberCursor(contactId);
    TextView phoneNumber = (TextView) view.findViewById(R.id.userNumber);
    while (phoneCursor.moveToNext()) {
        phoneNumber
                .setText(phoneCursor.getString(phoneCursor
                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
    }
}

private void setContactEmails(View view, String contactId) {
    Cursor emailCursor = cursorsForContacts.getEmailCursor(contactId);
    TextView userEmailId = (TextView) view.findViewById(R.id.userEmailId);
    while (emailCursor.moveToNext()) {
        userEmailId
                .setText(emailCursor.getString(emailCursor
                        .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)));
    }
}

@Override
public int getPositionForSection(int section) {
    return alphabetIndexer.getPositionForSection(section);
}

@Override
public int getSectionForPosition(int position) {
    return alphabetIndexer.getSectionForPosition(position);
}

@Override
public Object[] getSections() {
    return alphabetIndexer.getSections();
}

}
final boolean longList = childCount > 0 && itemCount / childCount >= MIN_PAGES;