0

这是 getContact 方法,在这种情况下采用 rowID 计数器

public Cursor getContact(long rowId) throws SQLException 
    {
        Cursor mCursor =
                db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                        question, possibleAnsOne,possibleAnsTwo, possibleAnsThree,realQuestion,userR}, KEY_ROWID + "=" + rowId, null,
                        null, null, null, null);
        if (mCursor != null) {
            // moves to the the first record
            mCursor.moveToFirst();
        }
        return mCursor;
    }

这是我的问题。我从记录一开始。所以计数器设置为1。

在公共 oncreate 方法中。当我出于某种原因单击下一步时,它没有使用 db.updateUserResult(counter,8); 设置第一条记录的值;我认为它缺少第一条记录。我知道这一点的原因是,如果我选择了前面的答案。假设问题 1 的正确答案是选项 2,问题 2 的正确答案是选项 3。如果您为问题 1 选择选项 3,那么您将得到正确答案。如果我继续选择正确的答案,我会得到所有正确的结果。

 public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);



            Bundle b = getIntent().getExtras(); 
            boolean TimerStarted = b.getBoolean("timerlogic");
            System.out.println("what is the logic of the timer" + TimerStarted);
            Log.e(LOGS, "Whatis the first value for the timer inside the timer_btn" + TimerStarted);

            setContentView(R.layout.basic);
            // this method is better then a try and catch block as it actually prevents the occurence occuring instead of just patching it.
            // the purpose of t
            db.open();

            Cursor c = db.getContact(1); 

            if(c.isFirst())
            {
                TextView question = (TextView)findViewById(R.id.question);
                RadioButton radio1 = (RadioButton)findViewById(R.id.radio1);
                RadioButton radio2 = (RadioButton)findViewById(R.id.radio2);
                RadioButton radio3 = (RadioButton)findViewById(R.id.radio3);





                answerCounterText = (TextView)findViewById(R.id.answerCounterText);
                answerCounterText.setText(String.valueOf("0")); 
                // for the first record set the counter to zero
                // question.setText(String.valueOf("0"));
                TextView QuestionNumber = (TextView)findViewById(R.id.QuestionNumber);
                Complete = (Button)findViewById(R.id.Continue);
                Complete.setBackgroundResource(R.drawable.complete);
                Complete.setVisibility(View.INVISIBLE);
                QuestionNumber.setText(String.valueOf("Question Number  :" + counter));

                  System.out.println("what is the setup counter after loop" + counter);




                //DisplayContact(c,radio1);
                DisplayRadioButton(c,radio1,radio2,radio3,question);

            }


          // }
          //  }
         // Previous = (Button)findViewById(R.id.Previous);
           Next = (Button)findViewById(R.id.Next);

           Next.setBackgroundResource(R.drawable.next);
           // get the results from the checked box


           Next.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                // Cursor c = db.getContact(1);

                /*
                if (firstrecordchosen)
                {
                    Cursor c = db.getContact(1);
                      System.out.println("what is the current value of the counter 0" + counter);
                    firstrecordchosen = false;
                }
                counter++;

                  */   
                counter++;
                 Cursor c = db.getContact(counter);

                    if (c.moveToFirst() && !c.isNull(0))        
                    {    
                         TextView question = (TextView)findViewById(R.id.question);
                        RadioButton radio1 = (RadioButton)findViewById(R.id.radio1);
                         RadioButton radio2 = (RadioButton)findViewById(R.id.radio2);
                         RadioButton radio3 = (RadioButton)findViewById(R.id.radio3);



                      TextView answerCounterText = (TextView)findViewById(R.id.answerCounterText);
                         TextView QuestionNumber = (TextView)findViewById(R.id.QuestionNumber);
                         RadioGroup radioGroup1 = (RadioGroup)findViewById(R.id.radioGroup1);

                         QuestionNumber.setText(String.valueOf("Question Number  :" + counter));
                         Log.e(LOGS, "default user set variable " + c.getString(5));
                         Log.e(LOGS, "real value" + c.getString(6));
                         System.out.println("what is the current value of the counter" + counter);




                    //  DisplayContact(c,radio1);
                   DisplayRadioButton(c,radio1,radio2,radio3,question);
                  final String questionOneDb = c.getString(5);
                  String radioOneIndex = "1";
                  String radioTwoIndex = "2";
                  String radioThreeIndex = "3";



                  // set the first question to have the right value

                  if(radio1.isChecked() )
                    {     
                        db.updateUserResult(counter,8);
                        if (questionOneDb.equals(radioOneIndex))
                        {

                            Log.e(LOGS, "correct" );    


                        rightAnswer(c,radio1,answerCounterText);
                        //  DisplayContact(c,radio1);
                        }
                        else
                        {

                            Log.e(LOGS, "wrong" );  
                        }


                    }




                    if(radio2.isChecked()  )
                    {

                        db.updateUserResult(counter,9);

                        if (questionOneDb.equals(radioTwoIndex))
                        {
                          System.out.println("is this counter being reached"); 
                        //  db.updateUserResult(1, 2);
                        //  db.updateUserResult(counter, 2);
                        // db.updateUserResult(recordval, 6);

                            Log.e(LOGS, "correct" );    


                        rightAnswer(c,radio1,answerCounterText);
                        }
                        else
                        {
                            Log.e(LOGS, "wrong" );      
                        }

                    }



                    if(radio3.isChecked()   )
                    { 
                        db.updateUserResult(counter,10);

                        if (questionOneDb.equals(radioThreeIndex))
                        {
                            Log.e(LOGS, "correct" );    
                        System.out.println("you have the right answer");
                        rightAnswer(c,radio1,answerCounterText);
                        }
                        else
                        {
                            Log.e(LOGS, "wrong" );      
                        }


                    }








                    }



                  /* when you get ot the last record you want to be able to close the db */
                    if (c.isAfterLast())

                    { 

                    // this halts the timer when there are no questiosn left
                   Next.setVisibility(View.GONE);
               //    Previous.setVisibility(View.GONE);
                   Toast.makeText(getBaseContext(), "More questions available in the full version PHPExpert " , Toast.LENGTH_LONG).show();
                   Complete.setVisibility(View.VISIBLE);
                    handler.removeCallbacks(timedTask);
                    db.close();

                  intentcalls();


                    }






            }
        });

           Home = (Button)findViewById(R.id.home_btn);
           Home.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i = new Intent(Basic_database_questionsActivity.this,AndroidGUIActivity.class);
                startActivity(i);


            }


           }); 



        }
4

2 回答 2

1

如果我没有完全错,你有一个时间问题。

首先你得到你的第一个问题并显示 UI(你的单选按钮和东西)。

您单击“下一步”按钮进行检查,如果选择的答案是正确的,对吗?

如果是这样,你就犯了一个错误,你首先增加了计数器,然后根据计数器查询问题(这将是下一个)。之后,您检查选择的单选按钮是否正确。由于您已经从数据库中读取了下一个问题,因此您可以将第一个问题的所选答案与第二个问题的存储答案进行核对。

希望这很清楚。

简短提示:尝试清理一些代码。不要将任何东西放在onCreate()更小的块中,这样您就可以更轻松地查看和遵循代码流......

于 2012-09-24T22:37:15.147 回答
0

尝试这个

Cursor c1 = mDbHelper.fetAll(); \\ or whatever your method is to get data from database.
if(c1.moveToFirst()){
     do{
        \\ Do what you want to do with it.

       }while(c1.moveToNext()); \\ this will move the cursor to next line.
    }
 c1.close(); \\ make sure you close it, else errors will pop up in LOGCAT.
于 2013-08-11T18:34:35.090 回答