Example usage for android.widget ListView getCheckedItemIds

List of usage examples for android.widget ListView getCheckedItemIds

Introduction

In this page you can find the example usage for android.widget ListView getCheckedItemIds.

Prototype

public long[] getCheckedItemIds() 

Source Link

Document

Returns the set of checked items ids.

Usage

From source file:org.totschnig.myexpenses.dialog.SelectFromTableDialogFragment.java

@Override
public void onClick(DialogInterface dialog, int which) {
    if (getActivity() == null || mCursor == null) {
        return;/*  ww w . j  a va  2  s  .  c  o  m*/
    }
    ListView listView = ((AlertDialog) dialog).getListView();
    SparseBooleanArray positions = listView.getCheckedItemPositions();

    long[] itemIds = listView.getCheckedItemIds();

    if (itemIds.length > 0) {
        ArrayList<String> labelList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            if (positions.valueAt(i)) {
                mCursor.moveToPosition(positions.keyAt(i));
                labelList.add(mCursor.getString(mCursor.getColumnIndex(getColumn())));
            }
        }
        onResult(labelList, itemIds);
    }
    dismiss();
}

From source file:org.totschnig.myexpenses.dialog.SelectFromMappedTableDialogFragment.java

@Override
public void onClick(DialogInterface dialog, int which) {
    if (getActivity() == null || mCursor == null) {
        return;/*  w ww  .j av  a 2s.c o  m*/
    }
    ListView listView = ((AlertDialog) dialog).getListView();
    SparseBooleanArray positions = listView.getCheckedItemPositions();

    long[] itemIds = listView.getCheckedItemIds();

    if (itemIds.length > 0) {
        ArrayList<String> labelList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            if (positions.valueAt(i)) {
                mCursor.moveToPosition(positions.keyAt(i));
                labelList.add(mCursor.getString(mCursor.getColumnIndex(KEY_LABEL)));
            }
        }
        ((MyExpenses) getActivity()).addFilterCriteria(getCommand(),
                makeCriteria(TextUtils.join(",", labelList), itemIds));
    }
    dismiss();
}

From source file:com.btmura.android.reddit.app.CommentListController.java

public void delete(ListView lv) {
    SparseBooleanArray checkedItemPositions = lv.getCheckedItemPositions();
    long[] checkedItemIds = lv.getCheckedItemIds();

    String[] checkedThingIds = new String[checkedItemIds.length];
    boolean[] hasChildren = new boolean[checkedItemIds.length];
    fillCheckedInfo(checkedItemPositions, checkedThingIds, hasChildren);

    Provider.deleteCommentAsync(context, accountName, hasChildren, checkedItemIds, getThingId(0),
            checkedThingIds);//from  w  w  w . ja  v a2  s  .com
}

From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java

@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case LOADER_ENTRIES:
        if (mExportMode) {
            final ListView listView = getListView();
            final long[] checkedItems = listView.getCheckedItemIds();
            for (int i = 0; i < mAdapter.getCount(); i++) {
                listView.setItemChecked(i, false);
            }//w  w w .  ja va 2  s  .co  m

            mAdapter.swapCursor(data);
            int pos;
            for (long checked : checkedItems) {
                pos = mAdapter.getItemIndex(checked);
                if (pos != ListView.INVALID_POSITION) {
                    listView.setItemChecked(pos, true);
                }
            }

            invalidateExportMenu();
        } else {
            mAdapter.swapCursor(data);
            setActivatedPosition(mAdapter.getItemIndex(mActivatedItem));
        }
        setListShown(true);
        break;
    case LOADER_CAT:
        if (data.moveToFirst()) {
            setCatName(data.getString(data.getColumnIndex(Tables.Cats.NAME)));
        } else {
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    final FragmentManager fm = getFragmentManager();
                    if (fm != null) {
                        fm.popBackStack();
                    }
                }
            });
        }
        break;
    }
}