私は運転スクールのテストアプリを開発しています。私はいくつかの助けが必要です。データベースからラジオボタンを入力してくださいandroid
<!-- language: lang-xml -->
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#AAC1E2" >
<LinearLayout
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/i1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enun"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<ImageView
android:id="@+id/i2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/e2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enun"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="@+id/radioGroup2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
が...×30回とテストを修正し、あなたが渡されたかどうかを示すだろうボタン:
は、私は、XMLのようなファイルを持っています。あなたは3つ以下の質問に失敗したときにテストに合格します。
質問は、このように格納されます
Id_question Id_topic Id_test質問AnswerA AnswerB AnswerC AnswerOK画像
- Id_question Id_topicとid_testは、整数フィールド
- ある質問とAnswerA-Cは、テキストフィールド
- ですAnswerOKは整数フィールドです。 AnswerAがOK = 1、AnswerB = 2、AnswerC = 3の場合
- イメージは、リソースフォルダから抽出された関連イメージの名前です。
データベースを使用してxmlの各フィールドにデータを設定します。
<!-- language: lang-java -->
Cursor c = adbh.query(bundle.getString("test"));
//"test"-->"SELECT question, image FROM table WHERE id_test = 1"
Integer i = 1;
if (c.moveToFirst()) {
do {
String path = c.getString(index);
String nimage = "i"+i;
int idImage = getResources().getIdentifier(nimage, "id", this.getPackageName());
ImageView image = (ImageView) findViewById(idImage);
int idDrawable = getResources().getIdentifier(ruta, "drawable", this.getPackageName());
image.setImageResource(idDrawable);
String nenun = "e"+i;
String enun = c.getString(anotherIndex);
int idEnun = getResources().getIdentifier(nenun, "id", this.getPackageName());
TextView txtenun = (TextView) findViewById(idEnun);
txtenun.setText(enun);
i++;
} while (c.moveToNext());
ラジオボタンはどのように設定できますか?クエリは "SELECT AnswerA、AnswerB、テーブルWHERE id_test = 1からのAnswerC"になります
そして私の最後の質問は、どのようにしてテストを修正できるかです。私は、ラジオボタンを押したまま(私は正確にはどういうわけか)配列に格納して、正しい答えと比較すると思います。クエリは "テーブルからWHERE id_test = 1を選択してください"となります。
例:答えの質問の
アレイ: 1 1 1 2 2 3 2 3 1 3 2 ...正解の アレイ: 3 2 1 2 2 3 2 3 2 2 2 .. 。
<!-- language: lang-java -->
for (int i=0; i<30; i++)
if (a[i] == b[i])
numberOfRightAnswers++;
いただきありがとうございます:)
私は非常に便利なあなたのアドバイスを見つけます。私はこの種のレイアウトが必要です。なぜなら、実際の試験では、あなたの目の前で一瞬にして質問間を簡単に移動できるからです:)画像は問題ではない、それらはすべて約20kbです。 – luismiyu
ラジオボタンのリスナーの例を教えてください。 – luismiyu
@luismiyu私の編集された答えを見てください。 – Luksprog