Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9042405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:28:55+00:00 2026-06-16T10:28:55+00:00

I am using the code below in a class extending DialogFragment. Before adding the

  • 0

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?

Thanks for your help!

Edit: In the debugger it is visible too. I step forward a few steps and the cursor position changes without calling moveToPosition.

@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));          
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:28:56+00:00Added an answer on June 16, 2026 at 10:28 am

    The code that you posted doesn’t change the Cursor’s position anywhere else.

    However, if cursor references the same Cursor used in a CursorAdapter bound to a ListView then when the Dialog is drawn it probably obscures part of a ListView forcing the ListView to redraw. This definitely changes the position.

    Solution: Either use moveToPosition() again in the OnClickListener or fetch an independent Cursor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating excel file using below code public class ResultSetToExcel { private HSSFWorkbook
I am using the below code in my test class , to load all
I am using the below JS code in order to change the class when
I am using List in C#. Code is as mentioned below: TestCase.cs public class
I have successfully scheduled local notifications in my app using the code below: Class
So, after much researching and using code below in a Class the items I'm
I am using code below, the session variables are declarated in Common class and
The code snippet below produces an error: #include <iostream> using namespace std; class A
I am extening AsyncTask in class and running below code in run method using
We are using the code below to automatically log a user into Magento before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.