I'm trying to develop a simple but custom drag and drop feature of recyclerview items. The idea is to drag a child to a specific view, represented by a FrameLayout, that is not a child of recyclerview.
When a child is dropped onto it it will be deleted otherwise it will simply return to its original position.
I can easily achieve this behaviour without any animation effect, but my purpose is to have smooth animation on the UP dragevent and on the restoration of the element. Now whenever a child is dragged, I create a DragShadow of it and I delete the child in the dataset and notify the removal with adapter.notifyItemRemoved(position).
The last one allows me to have simple remove animation provided by Recyclerview itself.
The Code will explain the mechanism better than words:
public boolean dragNdrop(View arg1, int position) {
// ------------------------
final RecyclerAdapter adapter= ListItemFragment.getAdapter();
/*Keep track of the position and the object for restoring purpose*/
ListItemFragment.indexAbruptedRemoved=position;
ListItemFragment.itemAbruptedRemoved=adapter.getItem(position);
ClipData clipData = ClipData.newPlainText("", "");
View.DragShadowBuilder dsb = new View.DragShadowBuilder(arg1);
arg1.startDrag(clipData, dsb, arg1, 0);
adapter.remove(position);
adapter.notifyItemRemoved(position);
//--------------------
}
getter method for the adapter:
protected static RecyclerAdapter getAdapter() {
return (RecyclerAdapter) recList.getAdapter();
}
dragNdrop is called by a drag listener in the custom adapter:
public void onBindViewHolder(MyHolder myHolder, int position) {
//----------------------------------
myHolder.rowCard.setLongClickable(true);
myHolder.rowCard.setOnClickListener(new MyClickListener.ContainerListener(context,
myHolder.getAdapterPosition(), rowObject, myHolder.imagePreView));
myHolder.rowCard.setOnLongClickListener(new MyClickListener.DragListener(context,
myHolder.getAdapterPosition(), myHolder.rowCard));
//----------------------------------
}
LongCLickListener:
static class DragListener implements View.OnLongClickListener {
private Context context;
private int position;
private View dragged;
DragListener(Context context, int position, View dragged) {
this.context = context;
this.position = position;
this.dragged = dragged;
}
#Override
public boolean onLongClick(View v) {
return ((MainActivity) context).dragNdrop(dragged, position);
}
}
The FrameLayout called trashPanel has the following code:
trashPanel.setOnDragListener(new View.OnDragListener() {
#Override
public boolean onDrag(View view, DragEvent dragEvent) {
int dragAction = dragEvent.getAction();
View dragView = (View) dragEvent.getLocalState();//this
//is properly the object we 've passed with startdrag()
switch (dragAction) {
case DragEvent.ACTION_DRAG_EXITED:
imageView.setImageDrawable(getResources().getDrawable(R.drawable.bowl));
break;
case DragEvent.ACTION_DRAG_ENTERED:
imageView.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.waste));
break;
case DragEvent.ACTION_DRAG_ENDED:
ended(view, dragEvent);
break;
case DragEvent.ACTION_DROP:
Log.i(TAG,"HALOOOOO DROPPED");
drop();
break;
}
return true;
}//[m] end on drag
private void drop() {
String itemToRemove = itemAbruptedRemoved.getSessionName();
Toast.makeText(getActivity(), "DELETED: " + itemToRemove+
" list length:"+items.size()+" adapter length:"+mAdapter.size(),
Toast.LENGTH_SHORT).show();
/**
* HAPTIC FEEDBACK
*/
Vibrator v = (Vibrator) getActivity().getSystemService(Service.VIBRATOR_SERVICE);
long pattern[] = {25, 25, 50};
v.vibrate(pattern, -1);// -1 to not repeat
}
private void ended(View view, DragEvent dragEvent) {
if ( dropEventNotHandled(dragEvent) ) {
mAdapter.insert(itemAbruptedRemoved, indexAbruptedRemoved);
mAdapter.notifyItemInserted(indexAbruptedRemoved);
//********---------->mAdapter.notifyDataSetChanged();
Log.i(TAG,"AGGIUNTO");
}
//change the image inside trash_panel
imageView.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.bowl));
//due to implementations detail it must be done in this way(otherwise mutithread exception is throwned)
view.post(new Runnable() {
public void run() {
/**
* Set animation for fabNew Button and trash_panel
* in order to make them smoothly disappear
* and place them in their original positions
*
*/
------------------------------------
}
});
}
private boolean dropEventNotHandled(DragEvent dragEvent) {
return !dragEvent.getResult();
}
});
The problem is that sometimes when I start to drag an item, I obtain the correct DragShadow, but the item removed is wrong.
In the code i higlited with ***----> the call to notifyDataSetChanged(), because if i call it, things work properly, but without animation.
I know there are utility classes such as ItemTouchHelper.Callback that should be used to manipulate the movement and animation of recyclerlist children, but I can't figure out how to manage to make them do what I want to do. I saw a couple of methods that could be used to achieve this, such as onChildDrawOver and onChildDraw, but i still don't know how to use them in order to intercept dragevent.DROP . I also know the existence of the interface for the LLM called ItemTouchHelper.ViewDropHandler that has the abstract method prepareForDrop, but I still don't know how to use it in a proper way.
Thanks in advance to everyone who will help me!
Take a look at ItemTouchHelper. It will allow you customize your drag drawing. See Support7Demos for an example implementation.
Related
I have a listview that contains some items, i want to allow the user to preview the data of a specific item by pressing and holding on the item. i want the preview window/popup to stay showed as long as the user is pressing.
I am trying to achivie the same preview functionality in IOS and instagram
i already implemented on longpress but not sure what to is the best thing to show to get a the desired result
lv.setAdapter(arrayAdapter);
lv.setLongClickable(true);
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
Log.v("long clicked", "pos: " +pos);
return true;
}
});
any hints on how to implement that or best way to implement it ?
Well I'm using recycler view with images.
To show the image I use the long press listener calling this method:
public void publicationQuickView(Post post){
View view = getLayoutInflater().inflate( R.layout.quick_view, null);
ImageView postImage = (ImageView) view.findViewById(R.id.ivFeedCenter);
ImageView profileImage = (ImageView) view.findViewById(R.id.ivUserProfile);
TextView tvUsername = (TextView) view.findViewById(R.id.txtUsername);
tvUsername.setText(post.user.name);
Picasso.with(this).load(post.picture).priority(Picasso.Priority.HIGH).noPlaceholder().into(postImage);
Picasso.with(this).load(post.user.picture).noPlaceholder().into(profileImage);
builder = new Dialog(this);
builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
builder.getWindow().setBackgroundDrawable(
new ColorDrawable(Color.TRANSPARENT));
builder.setContentView(view);
builder.show();
}
I inflate the layout and inject into a Dialog.
To dismiss the dialog I'm using the RecyclerView.OnItemTouchListener() like this:
rvUserProfile.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
#Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if(e.getAction() == MotionEvent.ACTION_UP)
hideQuickView();
return false;
}
#Override
public void onTouchEvent(RecyclerView rv, MotionEvent event) {
}
#Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}});
And finally:
public void hideQuickView(){
if(builder != null) builder.dismiss();
}
You could add a custom OnTouchListener to the view that represents a given item in you ListView (or RecyclerView or whatever). This allows you to detect when a gesture starts (i.e. first finger down) end ends (i.e. last finger up) or is canceled (e.g. gesture was actually a scroll and has been intercepted by the ListView).
The code you need to do that would look something like that:
itemView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int actionMasked = event.getActionMasked();
switch (actionMasked) {
case MotionEvent.ACTION_DOWN:
// show preview
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// hide preview
break;
default:
}
return true;
}
});
Edit: You may need to include some logic to detect a simple tap (e.g. measure if the whole gesture lasted not longer than ViewConfiguration.getTapTimeout()) and call v.performClick().
See the following answer on how to handle long press with recycler view: RecyclerView onClick
Once you have that, you can show a layout to display your data.
Check this out...
Implement a listener on long click listener
how to implement a long click listener on a listview
and then enable the visibiity of a hidden view. While doing that of course check this link out on how to enable dynamic position of the preview pane
How can I dynamically set the position of view in Android?
My ultimate goal is to stop the scroll in specific locations, so the objects being viewed are shown completely, and the solution I came up with is by checking the scrollX location of the view when the touch is released. I did have a momentum issue, as the scroll could still continue due to the scroll velocity also after catching the touch event, I solved that using MotionEvent.ACTION_CANCEL, which I am not happy with, as the scrollTo is optically pleasing, but the MotionEvent.ACTION_CANCEL kills its effect.
My question is, is there a more elegant way to do this? Ideal would be if I could simply instruct my ScrollView NOT to have momentum/velocity.
myView.setOnTouchListener(new HorizontalScrollView.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
event.setAction(MotionEvent.ACTION_CANCEL);
int x = myView.getScrollX();
if (x < 150)
myView.scrollTo(0,0);
else if (x<450)
myView.scrollTo(300,0);
else
myView.scrollTo(600,0);
}
return false;
}
});
If you want to scroll precisely to show specific view, this answer should help you. What you have to do is to call myView.scrollTo(0, view.getBottom()) or myView.smoothScrollTo(0, view.getBottom()) on UI thread. This way, view object will be displayed fully.
EDIT: It seems to me that what you're trying to achieve here is very close to what ViewPager does: your intention is to move between the views with a swipe/fling gesture, providing full visibility to the paged views contents.
If you were to use ViewPager, this is how your code may have looked:
viewPager.setAdapter(new PagerAdapter() {
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
#Override
public int getCount() {
return getViewCount();
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
View view = getViewAtPosition(position);
container.addView(view);
return view;
}
#Override
public void destroyItem(ViewGroup container, int position, Object view) {
container.removeView((View) view);
}
});
Where getViewCount() and getViewAtPosition() methods have to be implemented accordingly to how many displayed views you want and the way they are instantiated.
You should use an onScrollListener if you want to get the current position when the scrollView is scrolled.
scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
#Override
public void onScrollChanged() {
int scrollX = rootScrollView.getScrollX(); //for horizontalScrollView
int scrollY = rootScrollView.getScrollY(); //for verticalScrollView
//DO SOMETHING WITH THE SCROLL COORDINATES
}
});
I have an Activity, inside is ViewPager and inside is ListFragment with ListView items. I want define touch gesture for the items (drag, fling etc.).
I'm able to attach onTouchListener() to each ListView item View by overriding getView() of adapter.
Adapter adapter = new Adapter(blah, blah, blah) {
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View itemView = super.getView(position, convertView, parent);
itemView.setOnTouchListener(new View.OnTouchListener() {
blah, blah, blah
});
return itemView;
}
};
But I only receive MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP if it occurs inside triggering item View boundary. For example I'm not able to catch MotionEvent.ACTION_OUTSIDE.
My guess is, that my custom onTouchListener compete with listener of ViewPager and of Activity. I want to trigger these other listeners in some occasions, i.e. if user move to side, I want to slide the whole View inside ViewPager but if he push on the ListView item and move vertically, I want startDrag() of the item.
How to implement that?
Edit/ Currently, my custom listener on ListView items works along with ViewPager, which is great. I'm able to catch ListView item events as long as I don't move outside its View and I'm able to slide the whole View in ViewPager as well.
Edit/ I've rewrote my ListView into RecycledView and realized that if I attach listener to item View, the ViewPager catches almost all move events, while allowing only the click events to go through. I've also realized, that if I attach OnTouchListener to the RecycledList it is able to catch move events along with the ViewPager so it depends on which level I attach the Listener. Problem is, that in item View level I have available full reference to item, while when working with the list, I need to guess item position from event coordinates and then gather data from Adapter and RecycledView, which is extra work.
Edit/ it wasn't that hard after all. Luckily, RecycledView has findChildViewUnder(int xPos, int yPos) method, so getting the View was piece of cake.
Here's my implementation, if someone is interested
mRecycledView.setOnTouchListener(new View.OnTouchListener() {
int LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
float mItemViewHeight, mInitialY;
boolean mIsResolved;
final Handler mHandler = new Handler(Looper.getMainLooper());
final Runnable mLongPress = new Runnable() {
#Override
public void run() {
mIsResolved = true;
onLongClick();
}
};
#Override
public boolean onTouch(View v, MotionEvent me) {
switch (MotionEventCompat.getActionMasked(me)) {
case MotionEvent.ACTION_DOWN:
mInitialY = me.getY();
mActiveUserView = mRecycledView.findChildViewUnder(me.getX(), mInitialY);
if (mActiveUserView == null) { // clicked to RecycledView where's no item
mIsResolved = true;
} else {
mIsResolved = false;
mItemViewHeight = (float) mActiveUserView.getHeight();
mHandler.postDelayed(mLongPress, LONG_PRESS_TIMEOUT);
}
break;
case MotionEvent.ACTION_MOVE:
if (!mIsResolved) {
stopLongClickHandler();
// check for vertical upward move
if (mInitialY - me.getY() > mItemViewHeight) {
mIsResolved = true;
onVerticalDrag();
}
}
break;
case MotionEvent.ACTION_UP:
if (!mIsResolved) {
stopLongClickHandler();
mIsResolved = true;
onClick();
}
}
return !mIsResolved;
}
void stopLongClickHandler() {
mHandler.removeCallbacksAndMessages(null);
}
void onVerticalDrag() {
Log.e("DEBUG", "start drag");
}
void onLongClick() {
Log.e("DEBUG", "long click");
}
void onClick() {
Log.e("DEBUG", "short click");
}
});
I can suggest you replacing ListView with RecyclerView. Then read this tutorial: it contains almost every drag/swipe/touch implementations on RecyclerView clearly explained.
Can someone help me with my Syntax? I am dynamically adding some views(custom view) to a FrameLayout that is already defined in XML. those custom view's are different type or same type. I'm able to add views to the screen but unable delete a particular view (either it is same type or different) from ViewGroup. those custom view having onTouch().
Here i'm facing problem : unable to trigger for long click, always takes touch listener
I have to create two options here if user selects a view when long click on that
change background color
delete view.
EDIT : according to tao suggestion i am able to get index of long pressed view if there is no touch listener's to view. but i have to implement touch listeners along with long press...
How can I do this?
if each one of your views have a delete button or something like that, you can do that:
yourLayout.setTag(view);
on your delete part:
yourLayout.setOnLongClickListener(new Button.OnLongClickListener() {
public boolean onLongClick(View view) {
...
...
yourLayout.removeView((View) view.getTag());
return _value;
}
i hope it helps you.
Ok, your problem is "unable to trigger for long click, always takes touch listener", but this is not enought. I need more details:
which view you supposed to handle the long click, parent view or children view?
which listener you used to handle long click, android.view.View.setOnLongClickListener or android.view.GestureDetector?
actually I done the same job last week. My experiences is: do not using android.view.View.setOnLongClickListener neither android.view.GestureDetector, handle the long click on parent view by yourself. View.java is a good example.
EDIT:
I dont's have compiler on my hand, so I just typing the pseudo-code which will handle the long press by self, for the real-code, the View.java will give you the best answer.
Firstly, you need a runnable to implement your action
class CheckForLongPress implements Runnable {
public void run() {
if (getParent() != null) {
// show toast
}
}
}
Secondly, modify your onTouchEvent to detecting long press
boolean onTouchEvent(...) {
switch (event.getAction()) {
case MotionEvent.ACITON_DOWN:
// post a delayed runnable to detecting long press action.
// here mPendingCheckForLongPress is instance of CheckForLongPress
postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout());
...
break;
case MotionEvent.ACTION_MOVE:
// cancel long press action
if (distance(event, lastMotionEvent) > mTouchSlop) {
removeCallbacks(mPendingCheckForLongPress);
}
...
break;
case MotionEvent.ACTION_UP:
// cancel long press action
removeCallbacks(mPendingCheckForLongPress);
...
break;
EDIT again:
following is real code, not pseudo one, which is very simple and shows how to handle long press in View.onTouchEvent(), may it would be help.
public class ItemView extends View {
public ItemView(Context context) {
super(context);
}
public ItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ItemView(Context context, AttributeSet attrs) {
super(context, attrs);
}
Runnable mLongPressDetector = new Runnable() {
public void run() {
Toast.makeText(getContext(), "Hello long press", Toast.LENGTH_SHORT).show();
}
};
MotionEvent mLastEvent;
#Override
public boolean onTouchEvent(MotionEvent event) {
mLastEvent = MotionEvent.obtain(event);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
postDelayed(mLongPressDetector, ViewConfiguration.getLongPressTimeout());
break;
case MotionEvent.ACTION_MOVE:
final int slop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
if (Math.abs(mLastEvent.getX() - event.getX()) > slop ||
Math.abs(mLastEvent.getY() - event.getY()) > slop) {
removeCallbacks(mLongPressDetector);
}
break;
case MotionEvent.ACTION_UP:
removeCallbacks(mLongPressDetector);
break;
}
return true;
}
}
Look here:
http://developer.android.com/reference/android/view/View.html
there is a method that int getId(). so every view has an unique idetifier. you can use it for ever view.
Here my question is how can i identify the selected view from the
group of views when user touch on that view.
I assume TwoPointsDraw & OnePointDraw is extending View.
So in this case what you can do is after creating object of TwoPointsDraw.assign unique Id or Tag to it.
TwoPointsDraw drawView = new TwoPointsDraw(context);
drawView.setTag("unique identifier"); <-Must be object type
drawView.setId(unique id); <-must be integer type
And when you will click particular view.You can check its identity using.
view.getTag() or view.getId()
Snippet should look like
circle.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
Log.i("Long", v.getTag().toString());
return false;
}
});
Hope this helps you.
For your OnLongClickListener to work, you should return false when you detect a long click in your onTouch function!
For example:
In your GestureDetector, to give a chance for your onLongClickListener you should:
#Override
public boolean onDown(MotionEvent ev) {
return false;
// return super.onTouchEvent(ev);
}
Otherwise:
In your Views, implement the setOnLongClickListener function and save the onLongClickListener passed instance. Whenever a long click is detected, call the instance's onLongClick function.
I'm having a hard time trying to figure this out. I have a gridview of 8 buttons. At the moment I'm using an onItemClickListener to trigger the buttons actions, however this produces two problems for me.
1) The buttons action happens after the button has been unpressed.
2) Two buttons cannot the pressed at the same time, you must release the first button.
As I have learnt, an onTouchListener should resolve my first issue, though I'm not sure how to determine which button has been pressed. My code for the onItemClickListener is as follows
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(Activity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
Now with the above, I know exactly which button has been pushed. I believe the code for implementing as an onTouchListener is as follows
gridview.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return false;
}
}) {
How am I supposed to determine which button has been pressed using MotionEvent? Before I was getting passed 'position' and it made this fairly easy. I also need to account for if two or more buttons have been pushed simultaneously/without letting another one go.
Does anyone know how to achieve this?
Having hit this very issue recently and coming across this post in my quest for help, I wanted to add two things from what I did which seem to have worked:
1) I added the onTouchListener to the object in the adapter rather than the activity or gridview.
2) In the OnTouchListener, I looked for MotionEvent.ACTION_DOWN (first finger touch) and MotionEvent.ACTION_POINTER_DOWN (subsequent finger touches), this way I can get multitouches and process them immediately without waiting for the user to lift their finger(s).
Note that I called it ImageAdapter, even though I've added a TextView to each as that way I can use the TextView background for the image, but add invisible text to the TextView so it works with Talkback):
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return numCols * numRows;
}
public Object getItem(int position) {
return this;
}
public long getItemId(int position) {
return position;
}
// create a new TextView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView;
if (convertView == null) { // if it's not recycled, initialize some attributes
textView = new TextView(mContext);
} else {
textView = (TextView) convertView;
}
// place any other initial setup needed for the TextView here
// here's our onTouchListener
textView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
boolean returnValue;
int thePosition = v.getId();
// MotionEvent.ACTION_DOWN gets the first touch
// MotionEvent.ACTION_POINTER_DOWN gets any subsequent touches (if you place a second finger on the screen)
// Between these I can get touches as soon as they happen, including multitouch support, without needing to wait until the user lifts their finger.
if ((event.getAction() == MotionEvent.ACTION_DOWN) || (event.getAction() == MotionEvent.ACTION_POINTER_DOWN)) {
TextView textView;
if (v == null) { // if it's not recycled, initialize some attributes
textView = new TextView(mContext);
} else {
textView = (TextView) v;
}
// Do any processing based on the touch - I call a function and pass the position (number of cell, 1..n) and textview so can make changes to it as needed
ScreenTapped(thePosition, textView);
// I used a returnValue
returnValue = true;
} else returnValue = false;
return returnValue;
});
return textView;
} // getView
} //imageadapter
I am infact trying to figure the same thing out. I got as far as figuring out which gridcell has been clicked using the following code
public boolean onTouch(View v, MotionEvent me) {
float currentXPosition = me.getX();
float currentYPosition = me.getY();
int position = gridView.pointToPosition((int) currentXPosition, (int) currentYPosition);
Position gives you the number on the gridView, and you can supposedly retrieve that particular item as following
gridView.getItemAtPosition(position)
But that is where I am stuck. My gridView has Textview items in it, and I am having trouble converting the item to a textview and then performing operations on it.
Hope this helps!
When using gridView the philosophy is:
the grid view implements the onTouchLister
when touch happens onTouchLister gathers the coordinates (a lot :) )
for all ACTION_MOVE events
when the touch event is MOVE_UP, calculate the real positions under
the coordinates and return the item in the grid
So the solution would be:
In your activity where you have findViewById(some_grid_view)
//Register handler for the onTouch event of gridView in your activity
gridView.setOnTouchListener(new MyActivityOnTouchListener(this));
NOTE: my onTouch listener is implemented in another class (MyActivityOnTouchListener) instead of inside the activity
...then in the MyActivityOnTouchListener class you implement the onTouch method:
public class CalendarActivityOnTouchListener implements View.OnTouchListener {
private MyActivity myActivityContext;
private GridView mGridView;
private HashSet<Point> movementCoordinates = new HashSet<Point>;
//Constructor
public MyActivityOnTouchListener (MyActivity context){
this.myActivityContext= context;
mGridView= myActivityContext.getGridView(); //assign touched gridView into a local variable
}
#Override
public boolean onTouch(View v, MotionEvent event) {
/*
* NOTE:
* ACTION_MOVE fires events until you release it
* ACTION_UP once you release it fires it
*/
//while touching the grid a bunch of ACTION_MOVE events are dispatched
if (event.getAction() == MotionEvent.ACTION_MOVE) {
//gather all coordinates touched (in a set to avoid duplicates)
movementCoordinates.add(new Point((int)event.getX(), (int)event.getY()));
return true;
}
//Finally the finger is lifted
if (event.getAction() == MotionEvent.ACTION_UP) {
//convert all movementCoordinates gathered in the previous block into real grid positions
int position;
for(Point p : movementCoordinates){
Log.d("Luka", p.x +" / "+p.y);
position = calendarGridView.pointToPosition(p.x, p.y);
//...Do whatever with the position
}
}
}
}
Be careful about the pointToPosition() method because in some cases it can return -1 instead of the position behind the coordinates. For example, if you have a margin between items in the grid those coordinates cannot return a position, hence the -1
hope it helps...