Advertisement
Guest User

Untitled

a guest
Aug 7th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. gridview.setOnTouchListener(new OnTouchListener() {
  2. public boolean onTouch(View v, MotionEvent me) {
  3.  
  4. int action = me.getActionMasked();
  5. float currentXPosition = me.getX();
  6. float currentYPosition = me.getY();
  7. int position = gridview.pointToPosition((int) currentXPosition,
  8. (int) currentYPosition);
  9. if (action == MotionEvent.ACTION_UP) {
  10. /*Toast.makeText(activity,
  11. "Item Position : " + position + "Action Up",
  12. Toast.LENGTH_LONG).show();*/
  13.  
  14. //v.setBackgroundColor(activity.getResources().getColor(R.color.red));
  15. }
  16. if (action == MotionEvent.ACTION_DOWN) {
  17. /*Toast.makeText(activity,
  18. "Item Position : " + position + "Action Down",
  19. Toast.LENGTH_LONG).show();*/
  20. downPosition = position;
  21. //v.setBackgroundColor(activity.getResources().getColor(R.color.red));
  22. }
  23. if (action == MotionEvent.ACTION_MOVE) {
  24. /*Toast.makeText(activity,
  25. "Item Position : " + position + "Action Move",
  26. Toast.LENGTH_LONG).show();*/
  27.  
  28. if(position>downPosition)
  29. {
  30. for(int i = downPosition; i<position; i++)
  31. {
  32. gridview.getChildAt(i+1).findViewById(R.id.date).setBackgroundColor(activity.getResources().getColor(R.color.red));
  33. }
  34. }else{
  35. for(int i = position; i<downPosition ; i++)
  36. {
  37. gridview.getChildAt(i).findViewById(R.id.date).setBackgroundColor(activity.getResources().getColor(R.color.red));
  38. }
  39. }
  40.  
  41. }
  42. return true;
  43. }
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement