Android Question multiple choice quiz

hi, I'm trying to develop an app in which I test my users' English knowledge. I shared the source of my project so you can see what I've done. What I need to know is that how can I connect the radio buttons tags to the index of right answer (which I've set in database) within the radio buttons in each question? There are 25 questions and each of them contains three radio buttons and one of them is the right answer according to their indexes set in the database but the problem is whatever I do, only the third radio button is the right answer for the user which is not right. for example the right answer is second radio button (index = 1), but I cannot connect, first the three specific 3 radio buttons to a specific question, and second, the right answer index to the radio button tag. I appreciate your help.
 

Attachments

  • TaeenSho.zip
    460.2 KB · Views: 292

rodmcm

Active Member
Licensed User
Set up an array with each set of radio buttons placing an number in a single known array location. ( 1 to 3 say)
Then check number in array with the corresponding number in the answer array. if the same correct, if not fail.
 
Upvote 0
Hello rodmcm thank u, but it could be more understandable if u show how codes should be written. I did every single thing I could imagine would solve the problem but not worked and I got the same response, only option three was right which was not in fact.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Sorry, I have problems loading the layMain layout (and I don't want (cannot) to fight with this right now. Note that you shouldn't use that CustomListView class, but this one:
https://www.b4x.com/android/forum/t...oss-platform-customlistview.84501/post-535270)
, so I write here the code I would add:

B4X:
    csv = sq.ExecQuery("SELECT * FROM voc_tbl")
    Dim RightAnswerIndex As Int
    For i = 0 To csv.RowCount - 1
        csv.Position = i
        RightAnswerIndex = csv.GetInt("index") '<-- bad field name
        Dim p As Panel
        p.Initialize("")
        listvv.Add(p,230dip, RightAnswerIndex)
        p.LoadLayout("ll1")
        RBv(RightAnswerIndex)
        lblQv.Text = csv.GetString("question")
    Next

B4X:
Sub RBv(RightAnswerIndex As Int)
' ...
    rbtAnswer(0).Tag = (RightAnswerIndex = 0)
' ...
    rbtAnswer(1).Tag = (RightAnswerIndex = 1)
' ...
    rbtAnswer(2).Tag = (RightAnswerIndex = 2)
 
Upvote 0
I did all instructions u mentioned but I'm facing an error. the CustomListView that u uses is a class or a library? what u wrote is this (
listvv.Add(p,230dip, RightAnswerIndex)) but the CustomListView that I use has just 2 fields (listvv.Add(p,RightAnswerIndex)), and the error says object must first be initialized but I've initialized CustomListView
 
Upvote 0
Error occurred on line: 131 (CustomListView)

java.lang.RuntimeException: Object should first be initialized (B4XView).

at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)

at java.lang.reflect.Method.invoke(Native Method)

at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)

at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)

at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)

at java.lang.reflect.Method.invoke(Native Method)

at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)

at b4a.example.main.afterFirstLayout(main.java:104)

at b4a.example.main.access$000(main.java:17)

at b4a.example.main$WaitForLayout.run(main.java:82)

at android.os.Handler.handleCallback(Handler.java:751)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:154)

at android.app.ActivityThread.main(ActivityThread.java:6077)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
what u wrote is this (
listvv.Add(p,230dip, RightAnswerIndex))
This is what you wrote, because you were using that class.
What I added to your code is what you need to set the tag of the RadioButtons, based on your db table.

I suggested to use the B4X CustomListView because it is "better" (many reasons);
the CustomListView that u uses is a class or a library?
It is a pre-installed library library (you just have to select it, but remove the class before)
1588749363875.png
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
hi, I'm trying to develop an app in which I test my users' English knowledge. I shared the source of my project so you can see what I've done. What I need to know is that how can I connect the radio buttons tags to the index of right answer (which I've set in database) within the radio buttons in each question? There are 25 questions and each of them contains three radio buttons and one of them is the right answer according to their indexes set in the database but the problem is whatever I do, only the third radio button is the right answer for the user which is not right. for example the right answer is second radio button (index = 1), but I cannot connect, first the three specific 3 radio buttons to a specific question, and second, the right answer index to the radio button tag. I appreciate your help.
See this code snippet
 
Upvote 0
This is what you wrote, because you were using that class.
What I added to your code is what you need to set the tag of the RadioButtons, based on your db table.

I suggested to use the B4X CustomListView because it is "better" (many reasons);

It is a pre-installed library library (you just have to select it, but remove the class before)
View attachment 93412
thank u but the problem is not solved :(
this is the error I face
Untitlesssd.jpg

and the picture below shows all my codes
Untitsssssled.jpg

and this picture shows my checked libararies
libs.jpg

and this one is my application's UI which I cannot complile right now, and I'd had taken the picture before the shown error
Untitfffled.jpg
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
sure yeah but when I do the compression it doesn't lose kilobytes more so that i cannot send it here, what should I do?
Do you mean that when you use File - Export As Zip the zip file exceeds 500kb?
If so, use some tool (like 7-zip) to remove resource files (image files, mainly) and try to attach them separately.


Error line: 54
1588840043310.png


If listvv is a xCustomListView, you cannot add to a Panel that way, is must be created and added by Designer.
 
Upvote 0
Do you mean that when you use File - Export As Zip the zip file exceeds 500kb?
If so, use some tool (like 7-zip) to remove resource files (image files, mainly) and try to attach them separately.


Error line: 54
View attachment 93489

If listvv is a xCustomListView, you cannot add to a Panel that way, is must be created and added by Designer.
thank u, I added the CLV but now I have a question, there r 25 questions in the tab and each question has 3 radio buttons within which one is the correct answer, now how can I control the answers? I want to add a button at the end of the questions (one for all and not one for each) which is enabled only when all the questions are answered (whether true or false) by the user and when it's pressed, a messagebox shows up to inform how many questions out of 25 are answered correctly. how can I control it this way? sorry I'm asking too many questions, but the only reference I can use to learn b4a is this site. thank u. may I communicate u in whatsapp?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I would add some buttons after the xCLV, to complete the compilation of the questionnaire.
In the "Confirm button Click event", I would launch a routine that checks all the questions, analyzing (a For Each loop on the xCLV items) all the xCLV and perhaps highlighting the correct errors and answers in it (add some invisible views to each item).

You could also store the answers in a List, filling it with each click made on the radio buttons.
 
Upvote 0
I would add some buttons after the xCLV, to complete the compilation of the questionnaire.
In the "Confirm button Click event", I would launch a routine that checks all the questions, analyzing (a For Each loop on the xCLV items) all the xCLV and perhaps highlighting the correct errors and answers in it (add some invisible views to each item).

You could also store the answers in a List, filling it with each click made on the radio buttons.
Thank u, but mine doesn't have that start conversation option.
 
Upvote 0
Top