whats the equivilent of getCheckedItemCount() for API level < 11?

后端 未结 3 636
日久生厌
日久生厌 2021-01-05 05:15

I am using this method to check how many items on a list a checked and I get this error that this method is not available for any SDK older than 11.

What is the equi

3条回答
  •  无人及你
    2021-01-05 05:55

    The accepted answer didn't work for me (always returns 0), I had to use the following code:

    public static int getCheckedItemCount(ListView listView)
    {
        if (Build.VERSION.SDK_INT >= 11) return listView.getCheckedItemCount();
        else
        {
            int count = 0;
            for (int i = listView.getCount() - 1; i >= 0; i--)
                if (listView.isItemChecked(i)) count++;
            return count;
        }
    }
    

提交回复
热议问题