You need to listen and touch the GridView and find out the position number.
I recognize the number as follows:
GridView gv_month; gv_month.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //parent.getItemAtPosition(position).toString(); Log.d("MyLog","day : " + String.valueOf(position) });
Touch as follows:
gv_month.setOnTouchListener(new AdapterView.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event){ switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: switch (v.getId()) { case R.id.gv_month: fromPosition = event.getX(); default: break; } return true; case MotionEvent.ACTION_UP: switch (v.getId()) { case R.id.gv_month: float toPosition = event.getX(); if (fromPosition > toPosition){ Log.d("MyLog","LEFT"); } else if (fromPosition < toPosition){ Log.d("MyLog","RIGHT"); } default: break; } } return true; } return false; }
If I implement both listeners, then only the second one works. How to combine?
Log.d("MyLog","day : " + String.valueOf(position)
so why not put it after the line, for example,fromPosition = event.getX();
and transfer the position toX
. And how do you defineX
, also defineY
- Dred