Try to do it without the OnGestureListener interface and post the result.
Em 18 de abril de 2012 23:43, [email protected] <[email protected]> escreveu: > I implemented a gridview with 7 rows and 3 columns(7,3). > I am trying to get an item in gridview on touch. (want to get an > touched item not clicked item) > I can get an item but it is not the one I want. > > > Example: When I touched (2,2), I should get the item in (2,2). > Instead, I got the item in (3,2). > > Please check my source code as following: > > > :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: > > public class GridviewflickActivity extends Activity implements > OnGestureListener { > > private GridView gv; > private GestureDetector gestureDetecotr; > private GestureDetector.OnGestureListener gl; > private ImageView imageview; > private int dragposition; > private ImageAdapter ia; > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > gv=(GridView)findViewById(R.id.drag_grid); > ia=new ImageAdapter(this); > gv.setAdapter(ia); > gestureDetecotr = new GestureDetector(this); > > } > > public boolean dispatchTouchEvent(MotionEvent ev) { > System.out.println("dispatchTouchEvent"); > return gestureDetecotr.onTouchEvent(ev); > > } > > public class ImageAdapter extends BaseAdapter{ > private Context mContext; > > public ImageAdapter(Context c){ > mContext = c; > } > > public int getCount() { > return mThumbIds.length; > } > > public Object getItem(int position) { > return mThumbIds[position]; > } > > public long getItemId(int position) { > return position; > } > > public View getView(int position, View convertView, ViewGroup > parent) { > > ImageView imageView1; > if (convertView == null) { > imageView1 = new ImageView(mContext); > imageView1.setLayoutParams(new GridView.LayoutParams(85, > 85)); > imageView1.setScaleType(ImageView.ScaleType.CENTER_CROP); > imageView1.setPadding(8, 8, 8, 8); > } else { > imageView1 = (ImageView) convertView; > } > > imageView1.setImageResource(mThumbIds[position]); > return imageView1; > > } > > > private Integer[] mThumbIds = { > R.drawable.sample_2, R.drawable.sample_3, > R.drawable.sample_4, R.drawable.sample_5, > R.drawable.sample_6, R.drawable.sample_7, > R.drawable.sample_0, R.drawable.sample_1, > R.drawable.sample_2, R.drawable.sample_3, > R.drawable.sample_4, R.drawable.sample_5, > R.drawable.sample_6, R.drawable.sample_7, > R.drawable.sample_0, R.drawable.sample_1, > R.drawable.sample_2, R.drawable.sample_3, > R.drawable.sample_4, R.drawable.sample_5, > R.drawable.sample_6, R.drawable.sample_7 > }; > } > > > > @Override > public boolean onFling(MotionEvent e1, MotionEvent e2, float > velocityX, > float velocityY) { > System.out.println("onFling"); > > int x=(int)e1.getX(); > int y=(int)e1.getY(); > dragposition=gv.pointToPosition(x, y); > if (dragposition==gv.INVALID_POSITION){ > return false; > } > > int cnt=gv.getChildCount(); > int fvp=gv.getFirstVisiblePosition(); > imageview=(ImageView)gv.getChildAt(dragposition-fvp); > System.out.println("X: "+ x +" Y: " + y +" dragposition: > "+dragposition+" fvp: " +fvp); > > ................ > ................ > > return true; > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

