I have a weird problem with GridView. The
onItemClick(AdapterView parent, View v, int position, long id)
method is giving wrong position sometimes. The code i have:
public class ImageAdapter extends BaseAdapter {
......
}
gridview = (GridView) findViewById(R.id.gridview);
image_adapter = new ImageAdapter(this);
gridview.setAdapter(image_adapter);
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Log.e(TAG, "position = "+position);
}
}
My gridView is 3X3 grid and Image adapter has 9 piece on images. Based on what grid position user selects, the image pieces get shuffled.
This works fine if selecting grid position is done slowly. But if user keeps on tapping very quickly on any particular position, the "position" parameter in onItemClick method gets arbitrarily changed. Suppose my grid is
0 1 2
3 4 5
6 7 8
and user keeps on tapping at a quick pace on position 5, sometimes the "position" parameter in onItemClick reads 0 or 6.
Any idea what is the reason for this and what could be the solution?