>
> when I touched (2,2),I should get (2,2)  but I got item of (3,2) .
>
If you take out everything you are doing with your gesture listener, do you
have the same problem?

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Tue, Apr 17, 2012 at 8:19 PM, h...@isb.co.jp <h...@isb.co.jp> wrote:

> Hi,everyone.
>
> I am new to android.
>
> I implemented a gridview with 7 rows and 3 columns(7,3).
> I am trying to get item in gridview on touch.
> I can get item but it is not what I want.
>
> for example
> when I touched (2,2),I should get (2,2)  but I got item of (3,2) .
>
> Please check my source code as following,any idea is welcome.
>
>
> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to