我已经动态创建了多个 View ,在我的例子中是 textViews
。我给了他们身份证。我想要的是选择我滑动手指
的所有textViews
id。例如,如果有 TextView 说 A 和 B,当我将手指从 A 滑动到 b 时,我应该将 ID 保存在我的数组中。目前我正在学习触摸。我不知道如何实现它。
最好的问候
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;
}
};
最佳答案
你试过了吗ACTION_HOVER_ENTER和 ACTION_HOVER_EXIT? 它可能会成功。请参阅 onGenericMotionEvent 文档中的示例.
关于java - 在android中拖动手指时选择多个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10704250/