2015-09-30 24 views
-5

我想實現一個Android應用,其中包括一個部分,用戶可以在其中做一個測驗。因爲我有點新的Android應用程序開發,我想就如何落實測驗部分的一些建議,在佈局方面Android:如何實現測驗應用

我有一組問題,每個人都有答案,自己各自的選擇,從我從我的API檢索。

什麼是最好的容易實現的方法做到這一點? 我需要逐頁顯示每個問題(Q1 - > Q2 - > ...)。

我是否生成一組碎片?或者我以某種方式使用RecyclerView爲每個問題生成每個頁面?

任何指導將不勝感激,謝謝!

回答

2

這是一個廣泛的問題,但這裏有一些快速的想法讓你開始。

關閉我的頭頂,你可以有一個名爲QuestionActivity的活動(或任何你想要的),這將是顯示問題的主要容器。然後你將有一個QuestionFragment,它將顯示在QuestionActivity內部。每次你想顯示一個新問題時,你都會調用Fragment的newInstance()方法,每次在Bundle中傳入適當的數據以填充Fragment的佈局,然後使用片段事務替換Activity中的Fragment。

至於碎片本身,你也許可以做一個LinearLayout,在頂部有一個TextView來顯示問題,一組在下面的RadioButton,顯示一些多項選擇選項,然後是一個提交按鈕,用戶將使用提交他的答案。那麼你當然會得到所有的點擊事件這些東西來確定選擇哪個答案,等

你QuestionFragment佈局可能有這樣的事情開始...

<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> 

,這將產生一個結果看起來像這樣...

enter image description here

當然,這一切都是很基本的,但同樣的,你的問題是相當廣泛的。有大量的文檔可以告訴你如何實際編寫所有這些東西並將它們放在一起,但希望這會讓你開始。

祝你好運!

+0

感謝您的回答。這非常有幫助。對不起,也許我不知道如何正確表達我的問題。 – pogoyogo

0

我不知道你用什麼樣的視圖來顯示第一個測驗問題,但是通過改變當前控件的值,每個下一個問題應該顯示在同一個視圖中。

相關問題