Example usage for android.widget ListView setItemChecked

List of usage examples for android.widget ListView setItemChecked

Introduction

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

Prototype

public void setItemChecked(int position, boolean value) 

Source Link

Document

Sets the checked state of the specified position.

Usage

From source file:nl.spellenclubeindhoven.dominionshuffle.SelectActivity.java

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    if (DIALOG_MINIMUM <= id && id <= DIALOG_MINIMUM + dialogMimimumCount) {
        AlertDialog alertDialog = (AlertDialog) dialog;
        ListView list = alertDialog.getListView();

        int pos;//from  w w  w .j  a  v a  2 s.co  m
        if (cardSelector.getCondition(selectedGroup) == null) {
            pos = cardSelector.getLimitMinimum(selectedGroup);
            if (pos >= 1)
                pos++;
        } else {
            pos = 1;
        }

        list.clearChoices();
        list.setItemChecked(pos, true);
        list.setSelectionFromTop(pos, list.getHeight() / 2);
    } else if (DIALOG_MAXIMUM <= id && id <= DIALOG_MAXIMUM + dialogMaximumCount) {
        AlertDialog alertDialog = (AlertDialog) dialog;
        ListView list = alertDialog.getListView();
        int pos = cardSelector.getLimitMaximum(selectedGroup);
        list.clearChoices();
        list.setItemChecked(pos, true);
        list.setSelectionFromTop(pos, list.getHeight() / 2);
    }

    switch (id) {
    case DIALOG_SOLVE_ERROR: {
        AlertDialog alertDialog = (AlertDialog) dialog;
        alertDialog.setMessage(dialogMessage);
        break;
    }
    default:
        break;
    }

    super.onPrepareDialog(id, dialog);
}

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

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

    screenStep = ScreenStep.MENU;//from   w  w w .j a  v  a2s. co  m

    getSupportActionBar().setSubtitle(Constants.getSelectedCourseShortName());
    getSupportActionBar().setIcon(R.drawable.test);

    tagsAnswersTypeItemClickListener = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            ListView lv = (ListView) parent;
            int childCount = lv.getCount();
            SparseBooleanArray checkedItems = lv.getCheckedItemPositions();
            boolean allChecked = true;

            if (position == 0) {
                for (int i = 1; i < childCount; i++) {
                    lv.setItemChecked(i, checkedItems.get(0, false));
                }
            } else {
                for (int i = 1; i < childCount; i++) {
                    if (!checkedItems.get(i, false)) {
                        allChecked = false;
                    }
                }

                if (allChecked) {
                    lv.setItemChecked(0, true);
                } else {
                    lv.setItemChecked(0, false);
                }
            }
        }
    };

    tfAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    tfAdapter.add(getString(R.string.trueMsg));
    tfAdapter.add(getString(R.string.falseMsg));

    String selection = "id=" + Long.toString(Constants.getSelectedCourseCode());
    Cursor dbCursor = dbHelper.getDb().getCursor(Constants.DB_TABLE_TEST_CONFIG, selection, null);
    startManagingCursor(dbCursor);

    if (dbCursor.getCount() > 0) {
        if (isDebuggable) {
            Log.d(TAG, "selectedCourseCode = " + Long.toString(Constants.getSelectedCourseCode()));
        }

        test = (Test) dbHelper.getRow(Constants.DB_TABLE_TEST_CONFIG, "id",
                Long.toString(Constants.getSelectedCourseCode()));

        if (test != null) {
            selectNumQuestions();
        } else {
            Toast.makeText(this, R.string.testNoQuestionsCourseMsg, Toast.LENGTH_LONG).show();
            finish();
        }
    } else {
        Toast.makeText(this, R.string.testNoQuestionsMsg, Toast.LENGTH_LONG).show();
        finish();
    }

    setResult(RESULT_OK);
}

From source file:at.bitfire.davdroid.syncadapter.SelectCollectionsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final ListView listView = getListView();
    listView.setPadding(20, 30, 20, 30);

    View header = getActivity().getLayoutInflater().inflate(R.layout.select_collections_header, null);
    listView.addHeaderView(header);/*from ww w . j a v a 2s . c o  m*/

    final ServerInfo serverInfo = (ServerInfo) getArguments().getSerializable(KEY_SERVER_INFO);
    final SelectCollectionsAdapter adapter = new SelectCollectionsAdapter(serverInfo);
    setListAdapter(adapter);

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            int itemPosition = position - 1; // one list header view at pos. 0
            if (adapter.getItemViewType(itemPosition) == SelectCollectionsAdapter.TYPE_ADDRESS_BOOKS_ROW) {
                // unselect all other address books
                for (int pos = 1; pos <= adapter.getNAddressBooks(); pos++)
                    if (pos != itemPosition)
                        listView.setItemChecked(pos + 1, false);
            }

            getActivity().supportInvalidateOptionsMenu();
        }
    });
}

From source file:android.support.v7.app.AlertController.java

private void setupView() {
    final View parentPanel = mWindow.findViewById(R.id.parentPanel);
    final View defaultTopPanel = parentPanel.findViewById(R.id.topPanel);
    final View defaultContentPanel = parentPanel.findViewById(R.id.contentPanel);
    final View defaultButtonPanel = parentPanel.findViewById(R.id.buttonPanel);

    // Install custom content before setting up the title or buttons so
    // that we can handle panel overrides.
    final ViewGroup customPanel = (ViewGroup) parentPanel.findViewById(R.id.customPanel);
    setupCustomContent(customPanel);/*from  ww  w.  j a v a  2  s .c om*/

    final View customTopPanel = customPanel.findViewById(R.id.topPanel);
    final View customContentPanel = customPanel.findViewById(R.id.contentPanel);
    final View customButtonPanel = customPanel.findViewById(R.id.buttonPanel);

    // Resolve the correct panels and remove the defaults, if needed.
    final ViewGroup topPanel = resolvePanel(customTopPanel, defaultTopPanel);
    final ViewGroup contentPanel = resolvePanel(customContentPanel, defaultContentPanel);
    final ViewGroup buttonPanel = resolvePanel(customButtonPanel, defaultButtonPanel);

    setupContent(contentPanel);
    setupButtons(buttonPanel);
    setupTitle(topPanel);

    final boolean hasCustomPanel = customPanel != null && customPanel.getVisibility() != View.GONE;
    final boolean hasTopPanel = topPanel != null && topPanel.getVisibility() != View.GONE;
    final boolean hasButtonPanel = buttonPanel != null && buttonPanel.getVisibility() != View.GONE;

    // Only display the text spacer if we don't have buttons.
    if (!hasButtonPanel) {
        if (contentPanel != null) {
            final View spacer = contentPanel.findViewById(R.id.textSpacerNoButtons);
            if (spacer != null) {
                spacer.setVisibility(View.VISIBLE);
            }
        }
    }

    if (hasTopPanel) {
        // Only clip scrolling content to padding if we have a title.
        if (mScrollView != null) {
            mScrollView.setClipToPadding(true);
        }
    }

    // Update scroll indicators as needed.
    if (!hasCustomPanel) {
        final View content = mListView != null ? mListView : mScrollView;
        if (content != null) {
            final int indicators = (hasTopPanel ? ViewCompat.SCROLL_INDICATOR_TOP : 0)
                    | (hasButtonPanel ? ViewCompat.SCROLL_INDICATOR_BOTTOM : 0);
            setScrollIndicators(contentPanel, content, indicators,
                    ViewCompat.SCROLL_INDICATOR_TOP | ViewCompat.SCROLL_INDICATOR_BOTTOM);
        }
    }

    final ListView listView = mListView;
    if (listView != null && mAdapter != null) {
        listView.setAdapter(mAdapter);
        final int checkedItem = mCheckedItem;
        if (checkedItem > -1) {
            listView.setItemChecked(checkedItem, true);
            listView.setSelection(checkedItem);
        }
    }
}

From source file:net.reichholf.dreamdroid.fragment.NavigationFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (mCurrentListItem == position) {
        // Don't reload what we already see but close
        getMainActivity().showContent();
        return;//  w w  w.  j  av a  2 s.  co  m
    }

    mCurrent = (int[]) l.getItemAtPosition(position);

    // only mark the entry if it isn't a "dialog-only-item"
    // TODO find a reliable way to mark the current item...
    if (mHighlightCurrent) {
        CheckableImageButton btn = (CheckableImageButton) findViewById(R.id.buttonProfiles);
        btn.setChecked(false);

        if (mCurrent[4] == 0 || (mCurrent[4] == 2 && isTablet())) {
            l.setItemChecked(position, true);
            mCurrentListItem = position;
        } else {
            l.setItemChecked(position, false);
            if (mCurrentListItem > 0) {
                l.setItemChecked(mCurrentListItem, true);
            }
        }
    } else {
        l.setItemChecked(position, false);
    }

    onItemSelected(mCurrent[0]);
}

From source file:com.silentcircle.contacts.editor.GroupMembershipView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override// w w w  . j  a  v  a  2  s  .  co  m
public void onClick(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (mPopup != null && mPopup.isShowing()) {
            mPopup.dismiss();
            return;
        }
    } else {
        groupCheckDialogDismiss();
    }

    mAdapter = new GroupMembershipAdapter<GroupSelectionItem>(getContext(),
            R.layout.group_membership_list_item);

    mGroupMetaData.moveToPosition(-1);
    while (mGroupMetaData.moveToNext()) {
        long groupId = mGroupMetaData.getLong(GroupMetaDataLoader.GROUP_ID);
        if (groupId != mFavoritesGroupId && (groupId != mDefaultGroupId || mDefaultGroupVisible)) {
            String title = mGroupMetaData.getString(GroupMetaDataLoader.TITLE);
            boolean checked = hasMembership(groupId);
            mAdapter.add(new GroupSelectionItem(groupId, title, checked));
        }
    }

    mAdapter.add(new GroupSelectionItem(CREATE_NEW_GROUP_GROUP_ID,
            getContext().getString(R.string.create_group_item_label), false));

    ListView listView;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mPopup = new ListPopupWindow(getContext(), null);
        mPopup.setAnchorView(mGroupList);
        mPopup.setAdapter(mAdapter);
        mPopup.setModal(true);
        mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
        mPopup.show();
        listView = mPopup.getListView();
    } else {
        GroupCheckPopup.modeList = listView = new ListView(parent.getActivity());
        listView.setAdapter(mAdapter);
    }
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setOverScrollMode(OVER_SCROLL_ALWAYS);
    int count = mAdapter.getCount();
    for (int i = 0; i < count; i++) {
        listView.setItemChecked(i, mAdapter.getItem(i).isChecked());
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        groupCheckDialog(mAdapter);
    }
    listView.setOnItemClickListener(this);
}

From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
    case TIME_DIALOG_ID:
        ((TimePickerDialog) dialog).updateTime(mCalendar.get(Calendar.HOUR_OF_DAY),
                mCalendar.get(Calendar.MINUTE));
        break;/* w  w  w .  j a  va  2  s  . co  m*/
    case DATE_DIALOG_ID:
        ((DatePickerDialog) dialog).updateDate(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH),
                mCalendar.get(Calendar.DAY_OF_MONTH));
        break;

    case DIALOG_MULTIPLE_CATEGORY:
        final AlertDialog alert = (AlertDialog) dialog;
        final ListView list = alert.getListView();
        // been
        // selected, then uncheck
        // selected categories
        if (mVectorCategories.size() > 0) {
            for (String s : mVectorCategories) {
                try {
                    // @inoran fix
                    if (list != null) {
                        list.setItemChecked(mCategoryLength - Integer.parseInt(s), true);
                    }
                } catch (NumberFormatException e) {
                    log("NumberFormatException", e);
                }
            }
        } else {
            if (list != null) {
                list.clearChoices();
            }
        }

        break;

    }
}

From source file:org.ohmage.prompt.multichoice.MultiChoicePrompt.java

@Override
public View getView(Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ListView listView = (ListView) inflater.inflate(R.layout.prompt_multi_choice, null);

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    String[] from = new String[] { "value" };
    int[] to = new int[] { android.R.id.text1 };

    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < mChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mChoices.get(i).key);
        map.put("value", mChoices.get(i).label);
        data.add(map);/* w  ww  .  j  a v  a  2 s  .  c o m*/
    }

    SimpleAdapter adapter = new SimpleAdapter(context, data, R.layout.multi_choice_list_item, from, to);

    adapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            ((CheckedTextView) view).setText((String) data);
            return true;
        }
    });

    listView.setAdapter(adapter);

    if (mSelectedIndexes.size() > 0) {
        for (int index : mSelectedIndexes) {
            if (index >= 0 && index < mChoices.size())
                listView.setItemChecked(index, true);
        }
    }

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //SparseBooleanArray checkItemPositions = ((ListView)parent).getCheckedItemPositions();
            if (((ListView) parent).isItemChecked(position)) {
                mSelectedIndexes.add(Integer.valueOf(position));
            } else {
                mSelectedIndexes.remove(Integer.valueOf(position));
            }
        }
    });

    return listView;
}

From source file:roommateapp.info.droid.ActivityBuilding.java

/**
 * Show the room properties filter options.
 *//*  w  w w .j a  v  a  2 s.c om*/
public void showFilterOptions() {

    AlertDialog.Builder filter = new AlertDialog.Builder(this);
    filter.setTitle(getString(R.string.filtertitle));

    // Get the layout inflater
    LayoutInflater inflater = this.getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    View dialogview = inflater.inflate(R.layout.dialog_filter, null);
    filter.setView(dialogview);

    // Seekbar
    dialogView = (TextView) dialogview.findViewById(R.id.txt_filterroomsize);
    SeekBar seekbar = (SeekBar) dialogview.findViewById(R.id.seekBar_filter);
    int size = Preferences.getSize(getApplicationContext());
    size = (size == -1) ? 0 : size;

    seekbar.setProgress(size);
    dialogView.setText(getString(R.string.filter_msgP1) + " " + size + " " + getString(R.string.filter_msgP2));

    seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            int stepSize = 5;
            progress = ((int) Math.round(progress / stepSize)) * stepSize;
            seekBar.setProgress(progress);
            dialogView.setText(
                    getString(R.string.filter_msgP1) + " " + progress + " " + getString(R.string.filter_msgP2));
        }

        public void onStartTrackingTouch(SeekBar seekBar) {
            // Nothing here (:
        }

        public void onStopTrackingTouch(SeekBar seekBar) {

            Preferences.setSize(getApplicationContext(), seekBar.getProgress());
        }
    });

    // Checkbox list
    ListView choiceList;

    choiceList = (ListView) dialogview.findViewById(R.id.listFilter);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_multiple_choice, this.filterlist);

    choiceList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    choiceList.setAdapter(adapter);
    boolean[] filterChecked = this.filterActive;

    // Set the saved filter preferences
    for (int i = 0; i < filterChecked.length; i++) {
        choiceList.setItemChecked(i, filterChecked[i]);
    }

    choiceList.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            filterActive[arg2] = !filterActive[arg2];
        }
    });

    // Filter
    filter.setPositiveButton(getString(R.string.filter_set), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            Preferences.setFilters(getApplicationContext(), filterActive);
            createListViewAll();
            createListViewFreeRooms();
        }
    });

    boolean isFilterActive = false;
    for (int i = 0; i < filterChecked.length && !isFilterActive; i++) {

        isFilterActive = filterChecked[i];
    }

    // Clear the filter settings
    if (isFilterActive || (Preferences.getSize(getApplicationContext()) > 0)) {

        filter.setNegativeButton(getString(R.string.filter_reset), new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

                resetFilter();
            }
        });
    }

    filter.create();
    filter.setCancelable(false);
    filter.show();
}

From source file:universe.constellation.orion.viewer.OrionViewerActivity.java

void updateRotation() {
    RadioGroup rotationGroup = (RadioGroup) findMyViewById(R.id.rotationGroup);
    if (rotationGroup != null) { //nook case
        rotationGroup.check(controller.getRotation() == 0 ? R.id.rotate0
                : controller.getRotation() == -1 ? R.id.rotate90 : R.id.rotate270);
    }/*from   www.  j a  va  2 s. c o m*/
    ListView list = (ListView) findMyViewById(R.id.rotationList);
    if (list != null) {
        int index = getScreenOrientationItemPos(controller.getScreenOrientation());
        list.setItemChecked(index, true);
        list.setSelection(index);
    }
}