Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/03/2013, 18:15
sfvgekko
 
Fecha de Ingreso: abril-2011
Ubicación: Leon
Mensajes: 61
Antigüedad: 13 años
Puntos: 2
Respuesta: Listener para TextView

Bueno pues funciona con una matriz de textview por si a alaguien le puede ayudar pego aqui el codigo que me ha ahorrado centenares de lineas duplicadas.
Aunque seguro que tampoco es la forma correcta ya que en realidad creo unos 100 listener con el bucle cuando seguro que se puede hacer solo en uno pero bueno
por el momento no se me ocurre otra forma, si alguien propone algo nuevo genial.

TextView[] listaDeText;

listaDeText = new TextView[]{
(TextView)findViewById(R.id.TV1),
(TextView)findViewById(R.id.TV2),
(TextView)findViewById(R.id.TV3),
(TextView)findViewById(R.id.TV4),
etc...}

Y el listener asi:


for (int i=0; i <= 100; i++) {

listaDeText[i].setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

String newTag = v.getTag(R.string.miTag).toString();

}
});
}