3

在我的例子中,我动态地创建了多个视图textViews。我给了他们身份证。我想要的是选择textViewsi 所在的所有 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;
          }
         };
4

2 回答 2

0

你试过ACTION_HOVER_ENTER和 ACTION_HOVER_EXIT 吗?它可能会奏效。请参阅onGenericMotionEvent文档中的示例。

于 2012-05-22T15:45:18.447 回答
0

据我了解,试试这个;为您的所有s实现onTouchlistner并设置此侦听器,执行以下操作:TextViewonTouch()

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;
}

尝试不同ACTIONSMotionEvent

于 2012-05-22T15:47:08.303 回答