Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you know that no other part of your program will be using the tag associated with the Views that represent the items in the list, you could initialize this the first time getView() is called (when presumably the filter will be empty) and then use the value of the tag on later calls to determine whether or not the items are enabled. For example :</p> <pre><code> public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); Integer tag = (Integer) view.getTag(); if (tag == null) { tag = new Integer(position); view.setTag(tag); } view.setEnabled(isEnabled(tag.intValue())); return view; } </code></pre> <p>EDIT: Based on the replies below, if it's possible to use something other than Strings as the array elements, I would recommend the following. Create a new class used to represent the elements -</p> <pre><code> private class Element { private String myString; private int myIndex; @Override public String toString() { return myString; } } </code></pre> <p>then change the array from Strings to Elements :</p> <pre><code> Element items[] = new Element[100]; for(int i = 0; i &lt; items.length; ++i) { items[i] = new Element(); items[i].myString = "Item " + (i+1); items[i].myIndex = i; } </code></pre> <p>Finally, change the ArrayAdapter declaration and getView method to the following : </p> <pre><code> setListAdapter(new ArrayAdapter&lt;Element&gt;(this, R.layout.list_item, items) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); view.setEnabled(isEnabled(getItem(position).myIndex)); return view; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload