How to set selected item of ListView without scrolling view [Android]

I have ListView

with 10 items in it, when I set the 4th item in the ListView as selected, then mine ListView

gets scrolled and the fourth item is ListView

placed at the top of the screen.

I don't want to scroll ListView

when I call setSelected()

on a list item that is not in the view.

I also tried to scroll ListView

programmatically using scrollTo(0, 0);

, but it doesn't work.


source to share

9 replies

I think this is hardcoded and therefore not possible without scrolling



you can use listview.setChoiceMode (ListView.CHOICE_MODE_SINGLE); from

mListView.setItemChecked(pos, true);


Some selectors may need to be installed. Also see Google example IOSchedule app - great example about listview with multiple select controllers (there are a few bugs :))



Old question, but it might be helpful to someone. You can use setSelectionFromTop . It's pretty smart and you can use it like this:

getListView().setSelectionFromTop(selection, getListView().getHeight() / 2);


It only starts scrolling after the middle of the list:





could be your job.



DO NOT use setSelection ()!

I do it differently.

private AdapterView.OnItemClickListener oiclFolders = new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> adapterView, View view, int posi, long id) {
        // clear original selected item
        if ( mViewOrg!=null ) mViewOrg.setBackgroundDrawable(null);
        if ( view!=null ) {
            // define your own drawable to set as background
            mViewOrg = view;
        curSel = posi;    // to store which one is selected
        // Do NOT setSelection -> will auto scroll to top
        // mlvFolders.setSelection(posi);




This worked for me -

  • Set CHOICE_MODE_SINGLE when setting up a custom list -
  • Use setSelected () inside OnItemClickListener () as below -

    private void setup_view(View rootView) {
        listview = (ListView) rootView.findViewById(;
        if(listview != null) {
            listview.setAdapter(new MyAdapter(getActivity().getApplicationContext()));
    private OnItemClickListener onitemclicklistener = new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position,
                long id) {



You can override requestChildRectangleOnScreen

like this to get rid of scrolling:

    public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
        return false;




Here's what I did:

int top = listView.getChildAt(fixedChildIndex).getTop();

//set selected item, keep scroll position
listView.setSelectionFromTop(newIndex, top);


This keeps the child ListViews with the view index (ListView reuses views!) FixedChildIndex in place.

For example, if you want the highlight to keep using this:

int first = listView.getFirstVisiblePosition();
int fixedChildIndex = listView.getSelectedItemPosition() - first;
View newSelectedChild = listView.getChildAt(selectedViewIndex);


If you want to make sure the selected item is fully visible then use this line

//set selected item, keep scroll position and make sure it is completely visible
listView.setSelectionFromTop(newIndex, Math.min(Math.max(0,top), listView.getHeight()-newSelectedChild.getHeight()));


Where newSelectedChild is the kind of child you want to select. You can get it by following these steps:



Use setSelection(4)

to set the selection without scrolling if the new selection is visible.



All Articles