I have used grid view in my project. When I click on grid view item speedily, it calls the same method twice a time. But I slowly click, then it works perfectly.
In method below I call the dialog box. When I click the item it opens the dialog box but when I speedily click the item then dialog box open two times. What should I do to solve this?
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) {
showDialog(position);
}
});
I have solution for opening twice time method. I can define the below condition through solved it:
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
private long mLastClickTime = 0;
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) return;
mLastClickTime = SystemClock.elapsedRealtime();
grideProductAdd(position);
}
});