Skip to content Skip to sidebar Skip to footer

How To Make The First Item Of A Listview To Be Selected As Default At Startup?

There is a ListView in my App and the ListView has a selector. I want to make the first item of this ListView to be selected as default at the very startup of App, How? Can anyone

Solution 1:

yourlist.setItemChecked(position,true)

Solution 2:

You can do this by

yourListView.setSelection(0);
yourListView.getSelectedView().setSelected(true);

I hope this will help you

Solution 3:

This work for me. I hope this will help you. :)

@Override
    public View getView(int position, View convertView, ViewGroup parent) {

    // do someting...if(position == 0){
        mListView.performItemClick(convertView, 0, 0);
    }

 }

now i found another good way to implement this.

  • Firstly,you should set ListView android:choiceMode=singleChoice
  • Secondly,just go ahead as follow,

    int defaultPositon = 0;
        int justIgnoreId = 0;
        mListView.setItemChecked(defaultPositon, true);
        mListView.performItemClick(mListView.getSelectedView(), defaultPositon, justIgnoreId);
    

Solution 4:

I think this will work as we have given 0 index of array to listView

ListView.setSelection(0);

Solution 5:

//put the below code in get view function if(position==0)
{
    convertView.setSelected(true); 
}

Post a Comment for "How To Make The First Item Of A Listview To Be Selected As Default At Startup?"