我正在嘗試AlphabetIndexer使用自定義適配器來實(shí)現(xiàn)帶自定義適配器的AlphabetIndexer我的類ContactsCursorAdapter可以擴(kuò)展SimpleCursorAdapter和實(shí)現(xiàn),SectionIndexer 并且我正在使用A LoaderManager來管理適配器的游標(biāo),因此我已經(jīng)覆蓋了swapCursor()上述示例的第二個(gè)答案所示的方法。public class ContactsCursorAdapter extends SimpleCursorAdapter implements SectionIndexer{ private LayoutInflater mInflater; private Context mContext; private AlphabetIndexer mAlphaIndexer; public ContactsCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { super(context, layout, c, from, to); mInflater = LayoutInflater.from(context); mContext = context; } public View getView(final int position, View convertView, ViewGroup parent) { ... } @Override public int getPositionForSection(int section) { return mAlphaIndexer.getPositionForSection(section); } @Override public int getSectionForPosition(int position) { return mAlphaIndexer.getSectionForPosition(position); } @Override public Object[] getSections() { return mAlphaIndexer.getSections(); } public Cursor swapCursor(Cursor c) { // Create our indexer if (c != null) { mAlphaIndexer = new AlphabetIndexer(c, c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME), " ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } return super.swapCursor(c); }}但是,如果我將listview設(shè)置為fastScrollEnabled = true,則會出現(xiàn)此錯(cuò)誤getListView()。setFastScrollEnabled(true);在我的類ContactsCursorLoaderListFragment中,該類擴(kuò)展ListFragment并實(shí)現(xiàn)了LoaderManager.LoaderCallbacks。setFastScrollEnabled()調(diào)用該方法后,它將調(diào)用自定義適配器的getSections()崩潰方法。如果我對setFastScrollEnabled()呼叫進(jìn)行評論,那么它不會出錯(cuò),但是我看不到AlphabetIndexer工作原理。因?yàn)槲业淖远x適配器設(shè)置為ListFragment而不是,這是否需要以不同的方式實(shí)現(xiàn)ListActivity?有人對如何使這一切起作用有建議嗎?
由LoaderManager管理的具有自定義適配器的AlphabetIndexer
人到中年有點(diǎn)甜
2019-10-12 10:21:43