Example usage for android.widget ListView getCheckItemIds

List of usage examples for android.widget ListView getCheckItemIds

Introduction

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

Prototype

@Deprecated
public long[] getCheckItemIds() 

Source Link

Document

Returns the set of checked items ids.

Usage

From source file:org.planetmono.dcuploader.ActivityGalleryChooser.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    db = new DatabaseHelper(this);

    setContentView(R.layout.gallery_chooser);
    ((Button) findViewById(R.id.gallery_chooser_search)).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            String query = ((EditText) findViewById(R.id.gallery_chooser_edit)).getText().toString();

            if (query.length() > 0) {
                Message m = fetcherHandler.obtainMessage();
                m.getData().putString("searchTerm", query);
                fetcherHandler.handleMessage(m);
            } else {
                fetcherHandler.sendEmptyMessage(0);
            }/*from  w w  w .  j  av  a2s.com*/
        }
    });
    ((Button) findViewById(R.id.gallery_chooser_ok)).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ListView lv = (ListView) findViewById(R.id.gallery_chooser_list);

            long nids[] = lv.getCheckItemIds();
            String nstrs[] = new String[nids.length];

            for (int i = 0; i < nids.length; ++i)
                nstrs[i] = ids.get((int) nids[i]);

            Intent i = new Intent();
            i.putExtra("result", nstrs);

            setResult(Activity.RESULT_OK, i);
            finishActivity(Application.ACTION_ADD_GALLERY);
            finish();
        }
    });
    ((Button) findViewById(R.id.gallery_chooser_cancel)).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });

    if (db.rowCount() == 0)
        refresh();
    else
        fetcherHandler.sendEmptyMessage(0);
}

From source file:org.flerda.android.honeypad.NoteListFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.checkbox:
        Integer position = (Integer) v.getTag(R.id.list);
        if (null != position) {
            ListView lv = getListView();
            int pos = position;
            boolean isChecked = !lv.isItemChecked(pos);
            lv.setItemChecked(pos, isChecked);
            if (!mIsV11) {
                showMultiPanel();//ww  w.j a  v  a  2 s  . co  m
            }
        }
        break;
    case R.id.btn_multi_delete: {
        Activity a = getActivity();
        ContentResolver cr = a.getContentResolver();
        ListView lv = mLV;
        int deletedCount = 0;
        /** Badness. Don't loop a delete operation on the UI thread **/
        /** We also assume that the ID's and positions are constant **/
        for (long id : lv.getCheckItemIds()) {
            deletedCount += cr.delete(ContentUris.withAppendedId(NotesProvider.CONTENT_URI, id), null, null);
        }
        // clear any selections
        lv.clearChoices();

        // update container
        mContainerCallback.onNoteDeleted();

        // show a toast to confirm delete
        Toast.makeText(a,
                String.format(getString(R.string.num_deleted), deletedCount, (deletedCount == 1 ? "" : "s")),
                Toast.LENGTH_SHORT).show();
        showMultiPanel();
        break;
    }
    }
}