Java Code Examples for android.widget.ListView.getCheckedItemPositions()

The following are Jave code examples for showing how to use getCheckedItemPositions() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: godlibrary   File: CheckLayout.java   View Source Code Vote up 5 votes
public static long[] getCheckedItemIds(ListView listview) {
    List<Integer> list = new ArrayList<>();
    //listview.getCheckedItemPositions(); 为触发过选择的item ,选中 为true 取消false
    SparseBooleanArray sp = listview.getCheckedItemPositions();
    for (int i = 0; i < sp.size(); i++) {
        if (sp.valueAt(i)) {
            list.add(sp.keyAt(i));
        }
    }
    long[] ids = new long[list.size()];
    for (int i = 0; i < list.size(); i++) {
        ids[i] = list.get(i);
    }
    return ids;
}
 
Example 2
Project: orgzly-android   File: ListViewUtils.java   View Source Code Vote up 5 votes
public static TreeSet<Long> getCheckedIds(ListView listView) {
    TreeSet<Long> ids = new TreeSet<>();

    SparseBooleanArray checked = listView.getCheckedItemPositions();

    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i)) {
            long id = listView.getItemIdAtPosition(checked.keyAt(i));
            ids.add(id);
        }
    }

    return ids;
}