3

I have created multiple views dynamically , in my case textViews. i have given them ids. what iwant is to select all the textViews ids over which i slide my finger. E.g if there are textviews saying A And B and when i slide finger from A to b i should get ids save in my array. Currently I am learning touch. I don't know how to implement it.

Best Regards

  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;
          }
         };
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193
  • See here [http://stackoverflow.com/questions/21872464/get-button-coordinates-and-detect-if-finger-is-over-them-android][1] [1]: http://stackoverflow.com/questions/21872464/get-button-coordinates-and-detect-if-finger-is-over-them-android – Karthick pop Feb 27 '14 at 11:43

2 Answers2

0

Did you tried ACTION_HOVER_ENTER and ACTION_HOVER_EXIT? It might do the trick. See example in documentation of onGenericMotionEvent.

Marek R
  • 32,568
  • 6
  • 55
  • 140
0

From what I have understood, try this; Implement onTouchlistner and set this listener for all of your TextViews, in onTouch() do this:

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

Try different ACTIONS of MotionEvent

Ramzi Khahil
  • 4,932
  • 4
  • 35
  • 69
Sarim Sidd
  • 2,166
  • 2
  • 22
  • 31