在我的例子中,我动态地创建了多个视图textViews
。我给了他们身份证。我想要的是选择textViews
i 所在的所有 id slide my finger
。例如,如果有文本视图说 A 和 B,并且当我将手指从 A 滑动到 bi 时,应该将 ids 保存在我的数组中。目前我正在学习触摸。我不知道如何实现它。
此致
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;
}
};