搜尋此網誌

2015年11月12日 星期四

【Android】SparseBooleanArray 應用

ref:
checkboxes using SparseBooleanArray-StackOverflow
SparseArray淺析


....
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;
}

【Android】Material Design Example

ref:
http://wannadoitnow.blogspot.tw/2015/10/android-recyclerview-swiperefreshlayout.html
http://llzz.me/2015/09/29/Android-Support-Design-Library-CoordinatorLayout/
http://blog.csdn.net/zhangphil/article/details/48877721
http://www.jianshu.com/p/533f5ecee306