Seleccione Vistas múltiples mientras arrastra el dedo en Android
Frecuentes
Visto 1,860 veces
3
He creado múltiples vistas dinámicamente, en mi caso textViews
. Les he dado identificaciones. lo que quiero es seleccionar todos los textViews
identificadores sobre los que yo slide my finger
. Por ejemplo, si hay vistas de texto que dicen A y B y cuando deslizo el dedo de A a bi, debería guardar las identificaciones en mi matriz. Actualmente estoy aprendiendo el tacto. No sé cómo implementarlo.
Atentamente
OnTouchListener MyOnTouchListener = new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event)
{
Drawable d = getResources().getDrawable(R.drawable.small_corners);
switch(event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
vibe.vibrate(20);
id.add(v.getId());
TextView vv = (TextView) v;
val.add(vv.getText().toString());
vv.setBackgroundDrawable(d);
String str = "";
//A pressed gesture has started, the motion contains the initial starting location.
return false;
case MotionEvent.ACTION_POINTER_DOWN:
//A non-primary pointer has gone down.
break;
case MotionEvent.ACTION_MOVE:
//A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP).
int check = 0;
for (int i = 0; i < id.size(); i ++)
{
if (id.get(i) == v.getId())
check = 1;
}
if (check != 1)
{
id.add(v.getId());
vv = (TextView) v;
val.add(vv.getText().toString());
vv.setBackgroundDrawable(d);
}
return false;
case MotionEvent.ACTION_MASK:
//A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP).
break;
case MotionEvent.ACTION_OUTSIDE:
//A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP).
break;
case MotionEvent.ACTION_UP:
//A pressed gesture has finished.
break;
case MotionEvent.ACTION_POINTER_UP:
//A non-primary pointer has gone up.
break;
}
return false;
}
};
2 Respuestas
0
Lo intentaste ACTION_HOVER_ENTER y ACTION_HOVER_EXIT? Podría hacer el truco. Ver ejemplo en la documentación de onGenericMotionEvent.
contestado el 22 de mayo de 12 a las 16:05
No lo entiendo, ¿cómo configuraré este movimiento genérico con mi vista de texto? Muhammad Umar
0
Por lo que he entendido, prueba esto; Implementar onTouchlistner
y configure este oyente para todos sus TextView
pecado onTouch()
hacer esto:
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_MOVE){
//SAVE YOUR VIEWS ID//
someArray[index] = ((TextView)v).getId())
return true;
}
return false;
}
Prueba diferente ACTIONS
of MotionEvent
Respondido el 11 de Septiembre de 12 a las 00:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas java android or haz tu propia pregunta.
Mira aquí [stackoverflow.com/questions/21872464/… [1]: stackoverflow.com/questions/21872464/… - Karthick pop