2011-04-04 11 views
14

Así que tengo el siguiente código en el adaptador:Android - Desactivar elemento Listview clic y volver a habilitarlo

@Override 
    public boolean isEnabled(int position) 
    { 
     GeneralItem item = super.getItem(position); 
     boolean retVal = true; 


      if (item != null) 
      { 
       if (currSection != some_condition) 
       retVal = !(item.shouldBeDisabled()); 
      } 
     return retVal; 
    } 


    public boolean areAllItemsEnabled() 
    { 
     return false; 
    } 

La pregunta aquí: Así que si he deshabilitado mi artículo durante la unión inicial, ahora provocar el evento en la pantalla y necesita habilitarlos a todos sin importar nada. ¿Vuelvo a vincularlo nuevamente después de que se realiza esa acción?

por ejemplo:

onCreate{ 

// create and bind to adapter 
// this will disable items at certain positions 

} 

onSomeClick{ 

I need the same listview with same items available for click no matter what the conditions of positions are, so I need them all enabled. What actions should I call on the adapter? 

} 

El problema es que puedo tener una muy larga vista de lista también. Supone soportar 6000 artículos. Así que volver a enlazarlo ciertamente no es una opción.

Gracias,

Respuesta

25

¿Qué hay de tener una variable de instancia en el adaptador:

boolean ignoreDisabled = false; 

Luego, en areAllItemsEnabled:

public boolean areAllItemsEnabled() { 
    return ignoreDisabled; 
} 

y luego a principios de isEnabled:

public boolean isEnabled(int position) { 
    if (areAllItemsEnabled()) { 
     return true; 
    } 
    ... rest of your current isEnabled method ... 
} 

Luego puede cambiar entre los dos modos configurando ignoreDisabled de manera apropiada y llamando al invalidate en su ListView.

Tenga en cuenta que la adición a isEnabled probablemente no sea necesaria; simplemente parece un poco más completo.

+0

sí, así es exactamente como lo resolví :) ¡excelente respuesta, gracias! – dropsOfJupiter

Cuestiones relacionadas