如何在Android中使用光标数据创建列表数组 [英] How can I create a list Array with the cursor data in Android
本文介绍了如何在Android中使用光标数据创建列表数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用光标数据创建列表数组(滚动时列表显示第一个字母)?
How can I create a list Array (the list display First Alphabet when scroll) with the cursor data?
推荐答案
遍历Cursor
中的每一个元素,并将它们一一添加到ArrayList
中.
Go through every element in the Cursor
, and add them one by one to the ArrayList
.
ArrayList<WhateverTypeYouWant> mArrayList = new ArrayList<WhateverTypeYouWant>();
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));
}
(将 WhateverTypeYouWant
替换为您想要创建 ArrayList
的任何类型,并将 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.)
这篇关于如何在Android中使用光标数据创建列表数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文