Java Code Examples for android.widget.ListView#setItemChecked()

The following examples show how to use android.widget.ListView#setItemChecked() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.recyclerview_playground_fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActionBar().getThemedContext(),
            android.R.layout.simple_list_item_1,
            android.R.id.text1,
            new String[]{
                    "title_section1",
                    "title_section2",
                    "title_section3",
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
 
Example 2
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    mDrawerListView.setAdapter(new NavigationDrawerListAdapter(
            getActivity(),
            android.R.id.text1,
            new String[]{
                    getString(R.string.title_section_user),
                    getString(R.string.title_section1),
                    getString(R.string.title_section2)
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
 
Example 3
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mDrawerListView = (ListView) inflater.inflate(
                R.layout.fragment_navigation_drawer, container, false);
        mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectItem(position);
            }
        });
        mDrawerListView.setAdapter(new ArrayAdapter<String>(
                getActionBar().getThemedContext(),
                R.layout.adapter_navigation_drawer,
//                android.R.layout.simple_list_item_1,
                android.R.id.text1,
                new String[]{
                        getString(R.string.my_devices),
                        getString(R.string.logout),
                }));
        mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
        return mDrawerListView;
    }
 
Example 4
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false
    );
    mDrawerListView.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    selectItem(position);
                }
            }
    );
    mDrawerListView.setAdapter(
            new ArrayAdapter<String>(
                    getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, android.R.id.text1, new String[] {getString(R.string.title_section1), getString(R.string.title_section2), getString(R.string.title_section3),}
            )
    );
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
 
Example 5
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActionBar().getThemedContext(),
            android.R.layout.simple_list_item_1,
            android.R.id.text1,
            new String[]{
                    getString(R.string.nav_bar_chart),
                    getString(R.string.nav_stacked_bar_chart),
                    getString(R.string.nav_pie_chart),
                    getString(R.string.nav_value_line_chart),
                    getString(R.string.nav_cubic_value_line_chart),
                    getString(R.string.nav_vertical_bar_chart),
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
 
Example 6
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.recyclerview_playground_fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActivity(),
            android.R.layout.simple_list_item_activated_1,
            android.R.id.text1,
            new String[]{
                    "title_section1",
                    "title_section2",
                    "title_section3",
                    "title_section4",
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
 
Example 7
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Context context = getContext();
    if (context == null) return;

    Size[] resolutions = mIsEInkMode ? kEInkResolutions : kStandardResolutions;

    // add a radio button list
    int checkedItem = -1;
    final ArrayAdapter<String> resolutionsAdapter = new ArrayAdapter<>(context, android.R.layout.select_dialog_singlechoice);
    for (int i = 0; i < resolutions.length; i++) {
        Size size = resolutions[i];
        resolutionsAdapter.add(String.format(Locale.US, "%d x %d", size.getWidth(), size.getHeight()));

        if (size.equals(mResolution)) {
            checkedItem = i;
        }
    }

    ListView listView = view.findViewById(R.id.listView);
    listView.setAdapter(resolutionsAdapter);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    if (checkedItem >= 0) {
        listView.setItemChecked(checkedItem, true);
    }

    listView.setOnItemClickListener((parent, view1, position, id) -> {
        if (mListener != null) {
            Size[] currentResolutions = mIsEInkMode ? kEInkResolutions : kStandardResolutions;
            mListener.onResolutionSelected(currentResolutions[position], mIsEInkMode);
        }
    });

}
 
Example 8
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	mDrawerListView = (ListView) inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
	mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			selectItem(position);
		}
	});
	mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, android.R.id.text1, new String[] { getString(R.string.title_section1),
			getString(R.string.title_section2), getString(R.string.title_section3), }));
	mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
	return mDrawerListView;
}
 
Example 9
@Override
public void onDestroyActionMode(ActionMode mode) {
    Log.d(THIS_FILE, "onDestroyActionMode");

    ListView lv = getListView();
    // Uncheck all
    int count = lv.getAdapter().getCount();
    for (int i = 0; i < count; i++) {
        lv.setItemChecked(i, false);
    }
    mMode = null;
}
 
Example 10
private void actionModeInvertSelection() {
    ListView lv = getListView();

    for(int i = 0; i < lv.getCount(); i++) {
        lv.setItemChecked(i, !lv.isItemChecked(i));
    }
    mMode.invalidate();
}
 
Example 11
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActivity().getApplicationContext(),
            android.R.layout.simple_list_item_activated_1,
            android.R.id.text1,
            new String[]{
                    getString(R.string.title_section1),
                    getString(R.string.title_section2),
                    getString(R.string.title_section3),
                    getString(R.string.title_section4),
                    getString(R.string.title_section5),
                    getString(R.string.title_section6),
                    getString(R.string.title_section7),
                    getString(R.string.title_section8)
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
 
Example 12
Source Project: talk-android   File: RecipientEditTextView.java    License: MIT License 5 votes vote down vote up
@Override
public void onCheckedItemChanged(int position) {
    ListView listView = mAlternatesPopup.getListView();
    if (listView != null && listView.getCheckedItemCount() == 0) {
        listView.setItemChecked(position, true);
    }
    mCheckedItem = position;
}
 
Example 13
/** Called to select an item from the listview */
public void selectPosition(int position) {
    // Only if we're showing both fragments should the item be "highlighted"
    if (mDualFragments) {
        ListView lv = getListView();
        lv.setItemChecked(position, true);
    }
    // Calls the parent activity's implementation of the OnItemSelectedListener
    // so the activity can pass the event to the sibling fragment as appropriate
    mListener.onItemSelected(mCategory, position);
}
 
Example 14
private void checkAll(DialogInterface dialog, boolean val) {
    if (dialog == null) {
        return;
    }

    ListView lv = (ListView) ((AlertDialog) dialog).findViewById(R.id.searchListView);
    int size = lv.getCount();
    for (int i = 0; i < size; i++) {
        lv.setItemChecked(i, val);
        mClickedDialogEntryIndices[i] = val;
    }
}
 
Example 15
public void selectPageDialog() {
    if (context == null)
        context = App.getActivity();
    final int[] pages = new int[pagination.getAll()];

    for (int i = 0; i < pagination.getAll(); i++)
        pages[i] = i + 1;

    final ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setFastScrollEnabled(true);

    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setAdapter(new PaginationAdapter(context, pages));
    listView.setItemChecked(pagination.getCurrent() - 1, true);
    listView.setSelection(pagination.getCurrent() - 1);

    AlertDialog dialog = new AlertDialog.Builder(context)
            .setView(listView)
            .show();

    if (dialog.getWindow() != null)
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    listView.setOnItemClickListener((adapterView, view1, i2, l) -> {
        if (listView.getTag() != null && !((Boolean) listView.getTag())) {
            return;
        }
        selectPage(i2 * pagination.getPerPage());
        dialog.cancel();
    });
}
 
Example 16
Source Project: LibreTasks   File: ActivityLogTabs.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Update the UI display
 */
private void updateUI() {
  // Update the Log List since new logs may have been created
  LogAdapter logAdapter = new LogAdapter(this);

  listView = (ListView) findViewById(R.id.activity_logs_listview);
  listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
  listView.setAdapter(logAdapter);

  // Restore UI control values if possible.
  state = getSharedPreferences(KEY_STATE, Context.MODE_WORLD_READABLE
      | Context.MODE_WORLD_WRITEABLE);
  listView.setItemChecked(state.getInt(KEY_STATE_SELECTED_LOG, -1), true);
}
 
Example 17
protected boolean onSelectionActionItemClicked(final ActionMode mode, MenuItem item) {
    ListView listView = getListView();
    switch (item.getItemId()) {
        case R.id.blob_descriptor_delete:
            int count = listView.getCheckedItemCount();
            String countStr = getResources().getQuantityString(getDeleteConfirmationItemCountResId(), count, count);
            String message = getString(R.string.blob_descriptor_confirm_delete, countStr);
            deleteConfirmationDialog = new AlertDialog.Builder(getActivity())
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle("")
                    .setMessage(message)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            deleteSelectedItems();
                            mode.finish();
                            deleteConfirmationDialog = null;
                        }
                    })
                    .setNegativeButton(android.R.string.no, null).create();
            deleteConfirmationDialog.setOnDismissListener(new DialogInterface.OnDismissListener(){
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    deleteConfirmationDialog = null;
                }
            });
            deleteConfirmationDialog.show();
            return true;
        case R.id.blob_descriptor_select_all:
            int itemCount = listView.getCount();
            for (int i = itemCount - 1; i > -1; --i) {
                listView.setItemChecked(i, true);
            }
            return true;
        default:
            return false;
    }
}
 
Example 18
Source Project: coursera-android   File: TitlesFragment.java    License: MIT License 5 votes vote down vote up
@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
    if (mCurrIdx != pos) {
        mCurrIdx = pos;
        // Indicates the selected item has been checked
        l.setItemChecked(mCurrIdx, true);
        // Inform the QuoteViewerActivity that the item in position pos has been selected
        mListener.onListSelection(mCurrIdx);
    }
}
 
Example 19
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_encoding_list, null);
    list = (ListView) view.findViewById(android.R.id.list);
    SwitchCompat autoencoding = (SwitchCompat) view.findViewById(android.R.id.checkbox);
    autoencoding.setChecked(PreferenceHelper.getAutoEncoding(getActivity()));

    autoencoding.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            PreferenceHelper.setAutoencoding(getActivity(), isChecked);
        }
    });

    list.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.item_single_choice, encodings));
    list.setOnItemClickListener(this);

    String currentEncoding = PreferenceHelper.getEncoding(getActivity());

    for (int i = 0; i < encodings.length; i++) {
        if (currentEncoding.equals(encodings[i])) {
            list.setItemChecked(i, true);
        }

    }

    return new AlertDialog.Builder(getActivity())
            .setView(view)
            .create();
}
 
Example 20
Source Project: androidtestdebug   File: TitlesFragment.java    License: MIT License 4 votes vote down vote up
public void selectPosition(int position) {
    ListView lv = getListView();
    lv.setItemChecked(position, true);
    updateImage(position);
}