Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

-m - button, + layout clicks to reveal answer and go to next

  • Loading branch information...
commit 1a5d7b383681554eea024cbb7225435c1cdeaec4 1 parent c77999a
@demonview authored default_git_name committed
Showing with 21 additions and 15 deletions.
  1. +3 −7 res/layout/main.xml
  2. +18 −8 src/net/rapacity/inquisitor/MainActivity.java
View
10 res/layout/main.xml
@@ -2,7 +2,9 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="fill_parent">
+ android:layout_height="fill_parent"
+ android:clickable="true"
+ android:onClick="onClick">
<TextView
android:id="@+id/progress"
android:layout_width="fill_parent"
@@ -21,10 +23,4 @@
android:layout_height="wrap_content"
android:text="(answers)"
android:layout_below="@id/question"/>
- <Button
- android:id="@+id/nextQuestion"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/nextQuestion"
- android:layout_alignParentBottom="true"/>
</RelativeLayout>
View
26 src/net/rapacity/inquisitor/MainActivity.java
@@ -5,10 +5,12 @@
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
+import android.text.Html;
public class MainActivity extends Activity {
private Quiz quiz;
private int at;
+ private boolean revealed;
@Override
public void onCreate(Bundle bundle) {
@@ -16,16 +18,18 @@ public void onCreate(Bundle bundle) {
setContentView(R.layout.main);
quiz = new Quiz();
at = 0;
+ revealed = false;
+ updateDisplay();
+ }
- Button nextQ = (Button) findViewById(R.id.nextQuestion);
- nextQ.setOnClickListener(new Button.OnClickListener() {
- @Override
- public void onClick(View v) { nextQuestion(); updateDisplay(); }
- });
-
+ public void onClick(View view) {
+ if (revealed)
+ nextQuestion();
+ else
+ revealed = true;
updateDisplay();
}
-
+
private void updateDisplay() {
Question question = quiz.questions.get(at);
TextView tv;
@@ -39,11 +43,17 @@ private void updateDisplay() {
char letter = 'a';
for (String answer: question.getAnswers().keySet()) {
if (letter > 'a') tv.append("\n");
- tv.append(String.valueOf(letter++) + ". " + answer);
+ tv.append(String.valueOf(letter++) + ". ");
+ if (revealed && question.getAnswers().get(answer)) {
+ tv.append(Html.fromHtml("<font color=\"red\">" + answer + "</font>"));
+ } else {
+ tv.append(answer);
+ }
}
}
private void nextQuestion() {
+ revealed = false;
at = (at + 1) % quiz.questions.size();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.