Note that there are some explanatory texts on larger screens.

plurals
  1. PODialogFragment OnClickListener strange Cursor behavior
    text
    copied!<p>I am using the code below in a class extending DialogFragment. Before adding the buttons I move a cursor to a certain position (see setDataFromCursor()) The strange thing is, that the position has changed when trying to get the position again in the OnClickListener of the positive button. I added some Log output which proves that. Does anybody know why that happens?</p> <p>Thanks for your help!</p> <p>Edit: In the debugger it is visible too. I step forward a few steps and the cursor position changes without calling moveToPosition.</p> <pre><code>@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Log.v(TAG, "onCreateDialog"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); view = inflater.inflate(R.layout.query_tab_dialog_add_operation, null); name = (TextView) view.findViewById(R.id.editTextOPName); cimclass = (TextView) view.findViewById(R.id.editTextCIMclass); setDataFromCursor(); builder.setView(view) .setTitle( R.string.querytabfragment_dialog_editOperation_title) .setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { nameStr = name.getText().toString(); cimclassStr = cimclass.getText().toString(); Log.d(TAG, "cursor position: " + cursor.getPosition()); int id = cursor.getInt(0); Log.d(TAG, "cursor on item: " + id); // update affected row queryDBHelper.editCIMQuery(id, nameStr, cimclassStr); Log.d(TAG, "query edited. id: " + id + " name: " + nameStr + " cimclass: " + cimclassStr); cursor.requery(); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { EditOperationDialogFragment.this .getDialog().cancel(); } }); return builder.create(); } private void setDataFromCursor() { cursor.moveToPosition(cursorPosition); name.setText(cursor.getString(1)); cimclass.setText(cursor.getString(2)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload