I have tried many things to make this code work, it consists of showing an AlertDialog/description when taping on an element/marker from map. The problem is that 3 of 4 markers work (but not showing the right description. it looks like the previous one) and the last force closes the app with the logcat error:
CursorIndexOutOfBoundsException: Index 4 requested, with a size of 4
Code:
@Override
protected boolean onTap(int index) {
db = openHelper.getWritableDatabase();
String[] columns_descri = new String[] {COL_DESCR开发者_高级运维I};
Cursor cur = db.query(true, TABLE_COORD, columns_descri,null, null, null, null, null, null);
cur.moveToPosition(index);
String description = cur.getString(cur.getColumnIndexOrThrow(COL_DESCRI));
AlertDialog.Builder dialog = new AlertDialog.Builder(Geo.this);
dialog.setTitle("Infos.");
dialog.setMessage(description);
dialog.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
cur.close();
db.close();
return true;
}
you should not use directly index, instead, you probably have an adapter somewhere that can give you either the object you want to display or the _id of your row, which you can use to forge a precise request
edit
You are using a ItemizedOverlay. Therefore, you can get the tapped item by :
public void onTap(int index) {
Item item = getItem(index);
}
Then I suppose you can get the relevant informations from the item rather than from a cursor.
Just use cur.moveToPosition(index - 1);
精彩评论