Reputation: 155
I am using ontouch event but the problem i m having is it calls down event but it is nt calling move event or UP event check the following code
public class DragNewActivity extends Activity implements OnTouchListener {
private float X;
private float Y;
private int width;
private int height;
private CharSequence s;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("D","D");
TextView tv1 = (TextView)findViewById(R.id.tv1);
TextView tv2 = (TextView)findViewById(R.id.tv2);
tv1.setOnTouchListener(this);
//tv2.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
//int action = event.getAction();
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
Log.d("DOWN","DOWN");
break;
case MotionEvent.ACTION_MOVE:
Log.d("MOVE","MOVE");
break;
case MotionEvent.ACTION_UP:
Log.d("UP","UP");
X = event.getRawX();
Y = event.getRawY();
Display display = getWindowManager().getDefaultDisplay();
width=display.getWidth()/2;
height=display.getHeight()/2;
Log.e("X", X+"");
Log.e("Y", Y+"");
Log.e("ScX", width+"");
Log.e("ScY", height+"");
if(X>width && Y>height){
Log.e("SUFI", "Event ho gyuaaaaaaa");
}
break;
}
return false;
}
}
Upvotes: 3
Views: 11616
Reputation: 816
I know this is a bit old, but I think it's actually more accurate to say that the events happen in order:
Down -> Move -> Up.
The method "OnTouch" is called at least once for each event, and multiple times for onMove as it is being moved.
So, if you return false from Down, it won't move on to Move, then up.
If you return true from Down, it will continue to Move. If Move returns false, it will not move on to Up, and so on.
Upvotes: 0
Reputation: 4340
do not return false from ontouch return true so that it will listen next motion event
Upvotes: 7
Reputation: 30855
you need to return true instead of return false.
As you implement the onTouch it must be return true
Upvotes: 0