第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

由LoaderManager管理的具有自定義適配器的AlphabetIndexer

由LoaderManager管理的具有自定義適配器的AlphabetIndexer

我正在嘗試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?有人對如何使這一切起作用有建議嗎?
查看完整描述

1 回答

?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

所以我終于把這個(gè)工作了。這是我的做法:


我補(bǔ)充說:


ListView lv = getListView();

lv.setFastScrollEnabled(true);

lv.setScrollingCacheEnabled(true);

onLoadFinished()交換新游標(biāo)后的方法


public void onLoadFinished(Loader<Cursor> loader, Cursor data) { 

 // Swap the new cursor in.  (The framework will take care of closing the

 // old cursor once we return.)

 mAdapter.swapCursor(data);


 ListView lv = getListView();

 lv.setFastScrollEnabled(true);

 lv.setScrollingCacheEnabled(true);


}

因此,這三個(gè)語句已從onActivityCreated()我的自定義方法中刪除ListFragment。


查看完整回答
反對 回復(fù) 2019-10-12
  • 1 回答
  • 0 關(guān)注
  • 354 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號