unsweets.log

Frontend & Android.

getCheckedItemCount

Published at

getCheckedItemCountはAPI11からなのでこれをどこかに定義しておくと便利。

private static int getCheckedItemCount(AbsListView listView) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    return listView.getCheckedItemCount();
  else {
    int count = 0;
    SparseBooleanArray positions = listView.getCheckedItemPositions();
    for (int i = 0, l = positions.size(); l > i; i++)
      if (positions.valueAt(i))
        count++;
    return count;
  }
}