1
我在我的SQLite數據庫中有一個描述列,其中包含一些要粘貼到每個標記時顯示的文本。每個標記都有自己的描述。問題是當我點擊一個標記時,我會顯示所有其他AlertDialog
。我使用下面的代碼:在地圖上點擊標記結果在AlertDialog中顯示所有其他地圖標記
@Override
protected boolean onTap(int index) {
db = openHelper.getWritableDatabase();
String[] result_columns = new String[] {COL_DESCRI};
Cursor cur = db.query(true, TABLE_COORD, result_columns, null, null, null, null, null, null);
cur.moveToFirst();
while (cur.isAfterLast() == false) {
String description = cur.getString(cur.getColumnIndexOrThrow("description"));
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.moveToNext();
}
cur.close();
db.close();
return true;
}
的onTap
功能似乎工作:
protected boolean onTap(int index) {
db = openHelper.getWritableDatabase();
String[] result_columns = new String[] {COL_DESCRI};
Cursor cur = db.query(true, TABLE_COORD, result_columns, null, null, null, null, null, null);
cur.moveToPosition(index);
String description = cur.getString(cur.getColumnIndexOrThrow("description"));
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;
}
我知道我有一個指標分配到每一個AlertDialog
,但我不知道怎麼做。我試圖解決這個問題,但我似乎無法做到。有關如何解決問題的任何建議?
正是。你的意思是,我必須用'cur.moveToPosition(index)'替換'cur.moveToFirst()'並刪除'cur.moveToNext()'?爲什麼不推薦? – androniennn
不建議使用,因爲您應該只加載一次數據 - 將其綁定到視圖時。您尚未發佈此代碼,因此很難發表評論。您應該將其加載到本地集合中。然後,當用戶點擊一個項目時,只需按索引訪問正確的項目。 – ShibbyUK
我試過'cur.moveToPosition(index)',應用程序凍結,然後強制關閉。 – androniennn