Android Question Code Question Database

brianwiz12

Active Member
Licensed User
Longtime User
Hello,

Here is the example code i want to use

B4X:
Sub episode1_click
    Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "jerichobackground.png"))
    rbtAnswer1(0).Initialize("rbtAnswer")
    rbtAnswer1(0).Tag = 0
    pnle1.AddView(rbtAnswer1(0), 10dip, 60dip, 450dip, 75dip)
    rbtAnswer1(1).Initialize("rbtAnswer")
    rbtAnswer1(1).Tag = 1
    pnle1.AddView(rbtAnswer1(1), 10dip, 120dip, 450dip, 75dip)
    rbtAnswer1(2).Initialize("rbtAnswer")
    rbtAnswer1(2).Tag = 2
    pnle1.AddView(rbtAnswer1(2), 10dip, 180dip, 450dip, 75dip)
    If File.Exists(File.DirDefaultExternal, "SeasonOne.db") = False Then
        File.Copy(File.DirAssets, "SeasonOne.db", File.DirDefaultExternal, "SeasonOne.db")
    End If
    QuestionList.Initialize
    AnswerList1.Initialize
    AnswerList2.Initialize
    AnswerList3.Initialize
    RightIndex.Initialize
    xSQL.Initialize(File.DirDefaultExternal, "SeasonOne.db", True)

    xCursor = xSQL.ExecQuery("SELECT * FROM One ")
    Log(xCursor.RowCount)
    For i = 0 To xCursor.RowCount - 1
        xCursor.Position = i
        Log(xCursor.GetString("Question"))
        Log(xCursor.GetString("ChoiceOne"))
        Log(xCursor.GetString("ChoiceTwo"))
        Log(xCursor.GetString("ChoiceThree"))
        Log(xCursor.GetString("ansind"))
        Log(" ")
        QuestionList.Add(xCursor.GetString("Question"))
        AnswerList1.Add(xCursor.GetString("ChoiceOne"))
        AnswerList2.Add(xCursor.GetString("ChoiceTwo"))
        AnswerList3.Add(xCursor.GetString("ChoiceThree"))
        RightIndex.Add(xCursor.GetInt("ansind"))
    Next
    xCursor.Close
    btnNexte1_Click
End Sub

Sub rbtAnswer1_CheckedChange(Checked As Boolean)
    If Checked = True Then
        Dim rbt As RadioButton
        rbt = Sender
        If rbt.Tag = RightIndex.Get(Qnumber) Then
            Msgbox("Correct answer", "Result")
            btnNexte1_Click
        Else
            Msgbox("Wrong answer", "Result")
        End If
    End If
End Sub

Sub btnNexte1_Click
    Dim Result As Int

    Counter = Counter + 1
'    Qnumber = Rnd(0, 6)
    Qnumber = Counter Mod 10
'    If Qnumber >= 6 Then
'        Qnumber = 0
'    End If
    lblQuestione1.Text = QuestionList.Get(Qnumber)
 
    If Counter = 10 Then
        Result = Msgbox2("Episode One Completed", "Score", "Continue", "Finish", "", Null)
        Counter = 0
    End If
    rbtAnswer1(0).Checked = False
    rbtAnswer1(1).Checked = False
    rbtAnswer1(2).Checked = False
    rbtAnswer1(0).Text = AnswerList1.Get(Qnumber)
    rbtAnswer1(1).Text = AnswerList2.Get(Qnumber)
    rbtAnswer1(2).Text = AnswerList3.Get(Qnumber)
End Sub

Now It wont give me the pop up for correct or wrong answer when a selection is made.

If i change the sub RbtAnswer1_checkedChange to rbtanswer_checkedchange as below

B4X:
Sub rbtAnswer_CheckedChange(Checked As Boolean)
    If Checked = True Then
        Dim rbt As RadioButton
        rbt = Sender
        If rbt.Tag = RightIndex.Get(Qnumber) Then
            Msgbox("Correct answer", "Result")
            btnNexte1_Click
        Else
            Msgbox("Wrong answer", "Result")
        End If
    End If
End Sub

The pop up will appear for the correct and wrong answer. Afterward the rest of the program breaks. Is rbtanswer_checkedchange something that cannot be altered or be given different names?

I have rbtanswer1_checkedchange, 2,3,4,5,6 for different questions.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Hello,

...

The pop up will appear for the correct and wrong answer. Afterward the rest of the program breaks. Is rbtanswer_checkedchange something that cannot be altered or be given different names?

I have rbtanswer1_checkedchange, 2,3,4,5,6 for different questions.

If you want to use rbtanswer1_checkedchange, rbtanswer2_checkedchange, etc... you need to use the correct reference when you initialize the radio buttons - eg:

B4X:
    rbtanswer(0).initialize("rbtanswer1")
    rbtanswer(1).initialize("rbtanswer2")
    etc...

You say "Afterward the rest of the program breaks" - what is the issue?

- Colin.
 
Upvote 0
Top