How can I create a list Array with the cursor data in Android

前端 未结 5 1545
遥遥无期
遥遥无期 2020-12-04 12:18

How can I create a list Array (the list display First Alphabet when scroll) with the cursor data?

5条回答
  •  醉话见心
    2020-12-04 13:18

    Go through every element in the Cursor, and add them one by one to the ArrayList.

    ArrayList mArrayList = new ArrayList();
    for(mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) {
        // The Cursor is now set to the right position
        mArrayList.add(mCursor.getWhateverTypeYouWant(WHATEVER_COLUMN_INDEX_YOU_WANT));
    }
    

    (replace WhateverTypeYouWant with whatever type you want to make a ArrayList of, and WHATEVER_COLUMN_INDEX_YOU_WANT with the column index of the value you want to get from the cursor.)

提交回复
热议问题