2011-11-09 11 views
2

AlphabetIndexer、SectionIndexer、Custom CursorAdapterをカスタマイズされたListViewに使用しています。以下は同じもののためのコードです。しかし、私はリストをスクロールしながらアルファベットを見ることができません。私も次のリンクを試しましたhow to combine both DISPLAY_NAME and NUMBER in a customized CursorAdapter?AlphabetIndexerがカスタムListViewで動作しない

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(); 
} 

} 

私には何かが欠けていますか?

+0

私はここでシンプルなやり方をしています。http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42

+0

@Nikこれは同じです。ここで何かを見つけましたか?私の検索が成功しなかったために終了しました。 – JcDenton86

+0

[チュートリアル](https://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/) ? – JcDenton86

答えて

0

レイアウトxmlのListViewにandroid:fastScrollEnabled="true"を追加する必要があります。私の場合のアルファベットインデクサーでは遅すぎるOPが、受けることができます同じ質問をここでつまずく他の人々のためにおそらく

0

...

は、他の同じ画面に表示されていないが、いくつかの事例であり、「ランダム」でした。

リストがあまり長くなく、速いスクロールで、アルファベットインデクサーが中断されている場合に出てきます。正確な動作はAbsListViewのヘルパークラスであるクラスFastScrollerにあります。

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

MIN_PAGESがあり4.リストの項目数が少なくとも(児童数を4倍でない場合は、それを持っての値で定義される「リストが長い」場合を決定するが、コードの一部があります表示されている行)速いスクロールとアルファベットインデクサーは表示されません。

関連する問題