ref:
ContentProvider與ContentResolver
Android 原始碼徹底研究系列 - 鬧鐘程式, ContentProvider (5)
搜尋此網誌
2015年11月29日 星期日
2015年11月25日 星期三
2015年11月21日 星期六
2015年11月12日 星期四
【Android】SparseBooleanArray 應用
ref:
checkboxes using SparseBooleanArray-StackOverflow
SparseArray淺析
checkboxes using SparseBooleanArray-StackOverflow
SparseArray淺析
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
SparseBooleanArray checkedPositions = ((AlertDialog) dialog).getListView().getCheckedItemPositions(); | |
String print = ""; | |
int[] array = asIntArray(checkedPositions); | |
for (int i = 0; i < array.length; i++) { | |
print = print + " " + array[i]; | |
} | |
.... | |
private static int[] asIntArray(SparseBooleanArray checkedItems) { | |
int checked = 0; | |
// compute number of items | |
for (int i = 0; i < checkedItems.size(); i++) { | |
int key = checkedItems.keyAt(i); | |
if (checkedItems.get(key)) { | |
++checked; | |
} | |
} | |
int[] array = new int[checked]; | |
//add indexes that are checked | |
for (int i = 0, j = 0; i < checkedItems.size(); i++) { | |
int key = checkedItems.keyAt(i); | |
if (checkedItems.get(key)) { | |
array[j++] = key; | |
} | |
} | |
Arrays.sort(array); | |
return array; | |
} |
訂閱:
文章 (Atom)