Android: How to implement quiz app -
i'm trying implement android app includes part user can quiz. since i'm kinda new android app development, advice on how implement quiz part, in terms of layout
i have set of questions , each has own respective choice of answers retrieve api.
what best , easy implement approach this? i need display each question page page (q1 -> q2 -> ...).
do generate set of fragments? or somehow use recyclerview generate each page each question?
any guidance appreciated, thanks!
this kind of broad question, here quick ideas started.
off top of head, have activity called questionactivity (or whatever want), main container display questions. have questionfragment displayed inside questionactivity. each time want display new question, call fragment's newinstance() method, passing in appropriate data in bundle each time populate layout of fragment, replacing fragment in activity using fragment transaction.
as fragment itself, maybe linearlayout, textview @ top display question, set of radiobuttons below that, show multiple choice options, submit button under that, user use submit answer. of course receive click events these things determine answer selected, etc.
your questionfragment layout might start this...
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="com.david.timedtask.quizactivity"> <linearlayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:layout_centerhorizontal="true"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/quiz_question" android:id="@+id/textview" android:layout_gravity="center_horizontal" android:paddingbottom="100dp"/> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/option_one" android:id="@+id/radiobutton" /> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/option_two" android:id="@+id/radiobutton2" /> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/option_three" android:id="@+id/radiobutton3" /> <radiobutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/option_four" android:id="@+id/radiobutton4" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/submit_button" android:id="@+id/button" android:layout_margintop="50dp"/> </linearlayout> </relativelayout>
and produce result looking this...
of course pretty basic, again, question pretty broad. there plenty of docs available show how code stuff , put together, started.
good luck!
Comments
Post a Comment