Example usage for android.widget ListView setChoiceMode

List of usage examples for android.widget ListView setChoiceMode

Introduction

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

Prototype

public void setChoiceMode(int choiceMode) 

Source Link

Document

Defines the choice behavior for the List.

Usage

From source file:com.boardgamegeek.util.actionmodecompat.ActionModeHoneycomb.java

public static void beginMultiChoiceMode(ListView listView, FragmentActivity activity,
        final MultiChoiceModeListener listener) {
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        ActionModeHoneycomb mWrappedActionMode;

        @Override/*w w  w .  java 2  s.  c om*/
        public void onItemCheckedStateChanged(android.view.ActionMode actionMode, int position, long id,
                boolean checked) {
            listener.onItemCheckedStateChanged(mWrappedActionMode, position, id, checked);
        }

        @Override
        public boolean onCreateActionMode(android.view.ActionMode actionMode, Menu menu) {
            if (mWrappedActionMode == null) {
                mWrappedActionMode = new ActionModeHoneycomb();
                mWrappedActionMode.mNativeActionMode = actionMode;
            }
            return listener.onCreateActionMode(mWrappedActionMode, menu);
        }

        @Override
        public boolean onPrepareActionMode(android.view.ActionMode actionMode, Menu menu) {
            if (mWrappedActionMode == null) {
                mWrappedActionMode = new ActionModeHoneycomb();
                mWrappedActionMode.mNativeActionMode = actionMode;
            }
            return listener.onPrepareActionMode(mWrappedActionMode, menu);
        }

        @Override
        public boolean onActionItemClicked(android.view.ActionMode actionMode, MenuItem menuItem) {
            return listener.onActionItemClicked(mWrappedActionMode, menuItem);
        }

        @Override
        public void onDestroyActionMode(android.view.ActionMode actionMode) {
            listener.onDestroyActionMode(mWrappedActionMode);
        }
    });
}

From source file:ca.rmen.android.networkmonitor.app.prefs.SelectFieldsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Activity activity = getActivity();/*www. j  av a2 s  . com*/
    // Build the list of choices for the user.  Look up the friendly label of each column name, and pre-select the one the user chose last time.
    final String[] columnLabels = NetMonColumns.getColumnLabels(activity);
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(activity,
            android.R.layout.simple_list_item_multiple_choice, columnLabels);
    setListAdapter(adapter);
    ListView lv = getListView();
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    // Preselect the columns from the preferences
    List<String> selectedColumns = NetMonPreferences.getInstance(activity).getSelectedColumns();
    for (String selectedColumn : selectedColumns) {
        String selectedColumnLabel = NetMonColumns.getColumnLabel(activity, selectedColumn);
        int position = adapter.getPosition(selectedColumnLabel);
        lv.setItemChecked(position, true);
    }
}

From source file:com.example.android.hcgallery.TitlesFragment.java

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

    //Current position should survive screen rotations.
    if (savedInstanceState != null) {
        mCategory = savedInstanceState.getInt("category");
        mCurPosition = savedInstanceState.getInt("listPosition");
    }/*from www  .  j  av  a 2  s  .c  om*/

    populateTitles(mCategory);
    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    lv.setCacheColorHint(Color.TRANSPARENT);
    selectPosition(mCurPosition);
}

From source file:com.actionbarsherlock.sample.hcgallery.TitlesFragment.java

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

    //Current position should survive screen rotations.
    if (savedInstanceState != null) {
        mCategory = savedInstanceState.getInt("category");
        mCurPosition = savedInstanceState.getInt("listPosition");
    }//from w  w w .j  av a  2  s  . co m

    populateTitles(mCategory);
    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    lv.setCacheColorHint(Color.TRANSPARENT);
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
            final String title = (String) ((TextView) v).getText();

            // Set up clip data with the category||entry_id format.
            final String textData = String.format("%d||%d", mCategory, pos);
            ClipData data = ClipData.newPlainText(title, textData);
            v.startDrag(data, new MyDragShadowBuilder(v), null, 0);
            return true;
        }
    });

    selectPosition(mCurPosition);
}

From source file:dev.ronlemire.data.ListViewFragment.java

public void refresh(int index) {
    mCurCheckPosition = index;//w  w w . ja  v a 2s  . c  om

    // Populate list with our static array of titles.
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(parentActivity, R.array.list_titles,
            android.R.layout.simple_list_item_single_choice);
    setListAdapter(adapter);

    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    //lv.setItemChecked(mCurCheckPosition, true);
    //lv.performItemClick(lv, mCurCheckPosition, lv.getItemIdAtPosition(mCurCheckPosition));      
}

From source file:dev.ronlemire.dialogs.ListViewFragment.java

public void refresh(int index) {
    mCurCheckPosition = index;/*from w w w . j a  va2s  . co  m*/

    // Populate list with our static array of titles.
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(parentActivity, R.array.list_titles,
            android.R.layout.simple_list_item_single_choice);
    setListAdapter(adapter);

    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    lv.setItemChecked(mCurCheckPosition, true);
    lv.performItemClick(lv, mCurCheckPosition, lv.getItemIdAtPosition(mCurCheckPosition));
}

From source file:dev.ronlemire.receivers.ListViewFragment.java

public void refresh(int index) {
    mCurCheckPosition = index;//from ww  w .ja va  2  s.  c  o  m

    // Populate list with our static array of titles.
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(parentActivity, R.array.list_titles,
            android.R.layout.simple_list_item_single_choice);
    setListAdapter(adapter);

    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    lv.setItemChecked(mCurCheckPosition, true);
    //lv.performItemClick(lv, mCurCheckPosition, lv.getItemIdAtPosition(mCurCheckPosition));      
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = super.onCreateView(inflater, container, savedInstanceState);
    ListView l = (ListView) v.findViewById(android.R.id.list);
    l.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    l.setMultiChoiceModeListener(this);
    return v;//ww w . j a  v a2 s. co m
}

From source file:at.bitfire.davdroid.ui.AccountListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getLoaderManager().initLoader(0, getArguments(), this);

    ListView list = getListView();
    list.setOnItemClickListener(this);
    list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
}

From source file:monakhv.android.samlib.dialogs.SingleChoiceSelectDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.file_select, null);
    if (v == null) {
        Log.e(DEBUG_TAG, "Can not create View!!");
        return null;
    }/* ww  w  . j av a  2s.c  om*/
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_single_choice, data);

    ListView fileList = (ListView) v.findViewById(R.id.listFile);
    fileList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    fileList.setAdapter(adapter);
    fileList.setOnItemClickListener(listener);
    if (selected != -1) {
        fileList.setItemChecked(selected, true);
    }

    getDialog().setTitle(title);

    Button close = (Button) v.findViewById(R.id.listFile_close);
    close.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Log.d(DEBUG_TAG, "Close clicked");
            dismiss();
        }

    });
    return v;

}