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

  • SEARCH
  • Home
  • 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 7627235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:25:57+00:00 2026-05-31T05:25:57+00:00

I have used cursor on sqlite db for getting records . My code is

  • 0

I have used cursor on sqlite db for getting records .

My code is following:

btnnext.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        displayQuestion();
    });
}   

private void displayQuestion() {
    db.openDataBase();
    SQLiteDatabase sqlitedatabase = db.getWritableDatabase();

    Cursor cur;
    cur = sqlitedatabase.rawQuery("select quiz_id, opt_ans from options" ,null);
    cur.moveToFirst();
    db.close();

    radioGroup.removeAllViews();
    for (int i = 0; i <= 3; i++) {
        l++;
        Log.v("value of l",l+"");
        radioButton = new RadioButton(this);
        String str_opt = cur.getString(cur.getColumnIndex(Database_helper_class.OPT_ID));
        radioButton.setText(str_opt);
        Log.v("value of l",l+""+str_opt);
        radioButton.setId(i);
        cur.moveToPosition(l);
        radioGroup.addView(radioButton);
    }
}

and the log I am getting is :

03-07 18:32:03.190: V/value of l(28903): 1video
03-07 18:32:03.200: V/value of l(28903): 2
03-07 18:32:03.210: V/value of l(28903): 2sound
03-07 18:32:03.210: V/value of l(28903): 3
03-07 18:32:03.221: V/value of l(28903): 3image
03-07 18:32:03.231: V/value of l(28903): 4
03-07 18:32:03.240: V/value of l(28903): 4word document
03-07 18:32:05.561: V/value of l(28903): 5
03-07 18:32:05.571: V/value of l(28903): 5video
03-07 18:32:05.580: V/value of l(28903): 6
03-07 18:32:05.590: V/value of l(28903): 6A process
03-07 18:32:05.590: V/value of l(28903): 7
03-07 18:32:05.601: V/value of l(28903): 7A system software
03-07 18:32:05.601: V/value of l(28903): 8
03-07 18:32:05.610: V/value of l(28903): 8A document

and the db which I am using is

opt_ans,"opt_id","quiz_id"
    video,"1","1"
    sound,"2","2"
    image,"3","3"
    word document,"4","4"
    appliction,"5","5"
    A process,"6","6"
    A system software,"7","7"
    A document,"8","8"
    hgfhgfh,"9","9"
    hgfhgf,"10","10"
    tytrytr,"11","11"
    ytrytrytr,"12","12"
    tytrytrytr,"13","13"
    tytrytryt,"14","14"
    tytyt,"15","15"
    ytytyt,"16","16"
    ytytryt,"17","17"
    tytytr,"18","18"
    tytytryt,"19","19"
    htghyt,"20","20"

Now my question:

Why am I getting video on 5th and 9th index also while having different values at those indexes ??

  • 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-05-31T05:25:58+00:00Added an answer on May 31, 2026 at 5:25 am

    SQL does not guarantee any order of the returned rows, unless you specify. Basicly your results could be in random order. So you need to change your query as follows:

    cur = sqlitedatabase.rawQuery("select quiz_id, opt_ans from options order by quiz_id asc" ,null);
    

    EDIT
    Also I guess you are not iterating over the cursor properly, try this:

    int i = 0;
    for (boolean hasItem = cur.moveToFirst(); hasItem; hasItem = cur.moveToNext()) {
        if (i < 4) {
            radioButton = new RadioButton(this);
            String str_opt = cur.getString(cur.getColumnIndex(Database_helper_class.OPT_ID));
            radioButton.setText(str_opt);
            radioButton.setId(i);
            radioGroup.addView(radioButton);
            Log.v("Value of button " + i + " is: " + str_opt);
            i++;
        }
        else {
            break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have used the following Code to save date into DB of Sqlite (
I have used to following code to display the favorite item listing. It has
I have used traditional version control systems to maintain source code repositories on past
I have used IPC in Win32 code a while ago - critical sections, events,
I have used this code in my AS3 document class to remove all objects
I have used this code manually to simulate a mouse click by system through
I m executing following: db2 -tvsf ./sql/update_product.sql I have used eclipse for editing update_product.sql
I am new to android . I have an application working with SQLite DB.
in my application i have used sqlite database. I am able to insert the
I have used the XML Parser before, and even though it worked OK, I

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.