Android Question Panels Question

brianwiz12

Active Member
Licensed User
Longtime User
Hello,

Im working on multiple apps. In some cases tearing them down and starting over. I have made progress but have a question about panels.

Right now I use panels to load questions from a TV episode Trivia base i have created. Each episode has its own panel.

Any ideas if i can go with just one panel.

Example code im working with
B4X:
    Case "1"
            Counter = 0
            episode1_click
            pnle1.Visible = True
            lblwelcome.Visible = False
            pnle2.Visible = False
            pnle3.Visible = False
            pnle4.Visible = False
            pnle5.Visible = False
            pnle6.Visible = False
            pnle7.Visible = False
            pnle8.Visible = False
            pnle9.Visible = False
            pnle10.Visible = False
            pnle11.Visible = False
            pnle12.Visible = False
            pnle13.Visible = False
            pnle14.Visible = False
            pnle15.Visible = False
            pnle16.Visible = False
            pnle17.Visible = False
            pnle18.Visible = False
            
Sub episode1_click
    Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "jerichobackground.png"))
    rbtAnswer1(0).Initialize("rbtAnswer1")
    rbtAnswer1(0).Tag = 0
    pnle1.AddView(rbtAnswer1(0), 10dip, 60dip, 450dip, 75dip)
    rbtAnswer1(1).Initialize("rbtAnswer1")
    rbtAnswer1(1).Tag = 1
    pnle1.AddView(rbtAnswer1(1), 10dip, 120dip, 450dip, 75dip)
    rbtAnswer1(2).Initialize("rbtAnswer1")
    rbtAnswer1(2).Tag = 2
    pnle1.AddView(rbtAnswer1(2), 10dip, 180dip, 450dip, 75dip)
    If File.Exists(File.DirInternal, "fullerhouses3.db") = False Then
        File.Copy(File.DirAssets, "fullerhouses3.db", File.DirInternal, "fullerhouses3.db")
    End If
    QuestionList.Initialize
    AnswerList1.Initialize
    AnswerList2.Initialize
    AnswerList3.Initialize
    RightIndex.Initialize
    xSQL.Initialize(File.DirInternal, "fullerhouses3.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

The goes to episode Two panel 2 ect.

Now i did try to do it by putting it all in one button. (I will eventually go to a spinner but just trying to figure out if it will work) and the database does not mix itself plus i have to still make the subs for rbtanswer and btn to go to next question.

This is a long term thing im working on. I already fixed screen sizes thanks Erel for the video tutorial it was awesome! and made me understand it a lot better
 

mangojack

Expert
Licensed User
Longtime User
Just a few thoughts ...

Firstly , It appears you have a separate DB for each TV series , which contains a single Table "One", Two? that is Loaded / Initialized as you go.
... Check for existence / Initialize once only in the Starter service . The single DB contains a separate Table for all the Series.

Create a Single Panel Layout with all the necessary views. ( In Designer )

Choosing a Tv Series from Panel of Labels / Spinner etc , arms you with a Tag / Title which is saved to a global Variable.

This variable can be used to load images ... again doing away with long Case statements.
eg: Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, $"${TVSeriesTitle}.png"$)) *not tested ... search for Smart String Literals.

... and also access the relevant DB Table etc.


You can use some logic to ensure the correct answers do not always end up in the same RadioButtons etc.

As you said this is a long term thing ... but something tells me with a little bit of thought (and work) you will do away with many, many lines of duplicated code.
 
Upvote 0
Top