【问题标题】:Select Multiple Views while dragging finger in android在android中拖动手指时选择多个视图
【发布时间】:2012-05-22 14:36:33
【问题描述】:

我已经动态创建了多个视图,在我的例子中是 textViews。我给了他们身份证。我想要的是选择我slide my finger 的所有textViews id。例如,如果有文本视图说 A 和 B,并且当我将手指从 A 滑动到 b 时,我应该将 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;
          }
         };

【问题讨论】:

标签: java android


【解决方案1】:

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

【讨论】:

  • 不明白,我将如何用我的 textView 设置这个通用动作
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多