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

The following examples show how to use android.widget.ListView#setItemChecked() . 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
Source File: NavigationDrawerFragment.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@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
Source File: NavigationDrawerFragment.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: NavigationDrawerFragment.java    From EazeGraph with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: NavigationDrawerFragment.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
@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
Source File: NavigationDrawerFragment.java    From freeiot-android with MIT License 6 votes vote down vote up
@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 6
Source File: NavigationDrawerFragment.java    From giraff-android with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 7
Source File: NavigationDrawerFragment.java    From MultiView with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: RecipientEditTextView.java    From talk-android with 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 9
Source File: TitlesFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/** 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 10
Source File: SearchableMultiSelectPreference.java    From redalert-android with Apache License 2.0 5 votes vote down vote up
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 11
Source File: PaginationHelper.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
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 12
Source File: CallLogListFragment.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private void actionModeInvertSelection() {
    ListView lv = getListView();

    for(int i = 0; i < lv.getCount(); i++) {
        lv.setItemChecked(i, !lv.isItemChecked(i));
    }
    mMode.invalidate();
}
 
Example 13
Source File: ActivityLogTabs.java    From LibreTasks with 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 14
Source File: CallLogListFragment.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@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 15
Source File: NavigationDrawerFragment.java    From RedEnvelopeAssistant with MIT License 5 votes vote down vote up
@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 16
Source File: BlobDescriptorListFragment.java    From aard2-android with GNU General Public License v3.0 5 votes vote down vote up
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 17
Source File: TitlesFragment.java    From coursera-android with 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 18
Source File: EncodingDialog.java    From turbo-editor with GNU General Public License v3.0 5 votes vote down vote up
@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 19
Source File: ImageTransferFormatSelectorPageFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@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 20
Source File: TitlesFragment.java    From androidtestdebug with MIT License 4 votes vote down vote up
public void selectPosition(int position) {
    ListView lv = getListView();
    lv.setItemChecked(position, true);
    updateImage(position);
}