Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: disable ListView selection

Tags:

I have a listView that I re-display with the correct answer highlighted when the user selects an item. However, at that point I would like to disable selection of list view items; the user can only get to the next question by pressing a button. However, even if I disable the items like so:

   private void disableItemSelection() {         ListView lv = getListView();         for (int i = 0; i < lv.getChildCount(); i++){             View v = lv.getChildAt(i);             v.setEnabled(false);         }     } 

...it still highlights the selection when the user selects it. Any thoughts?

like image 573
Jack BeNimble Avatar asked Jun 04 '11 13:06

Jack BeNimble


1 Answers

The reason the scrolling is locked is because you are setting up at

ListView 

I found a way to disable highlighting without locking the scroll. You need to set it up at ListAdapter as shown below:

ArrayAdapter<String> myList = new ArrayAdapter<String>(this, R.layout.list_item, strText) {            public boolean isEnabled(int position)              {                      return false;              }          }; 
like image 183
aerobrain Avatar answered Oct 02 '22 17:10

aerobrain