1

SQLite データベースに、すべてのマーカーにテーピングするときに表示するテキストを含む説明列があります。すべてのマーカーには独自の説明があります。問題は、1 つのマーカーをタップすると、他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;
        }

every にインデックスを割り当てる必要があることは承知していますがAlertDialog、その方法がわかりません。これを解決しようとしましたが、できないようです。問題を解決する方法について何か提案はありますか?

4

1 に答える 1

2

結果のすべてのアイテムをループしているようです。

cur.moveToFirst()は最初の項目に移動し、次にcur.moveToNext(); 各反復で次の項目に移動します。次に、すべてのアイテムの警告ダイアログを表示しています!

ユーザーがアイテムをクリックするたびにこのようなデータをロードする必要はありませんが、コードを修正する最も簡単な [推奨されません] 方法は、ループの代わりにcur.moveToPosition(index)を使用することです。

于 2011-08-23T16:09:44.513 に答える