UI陷入测验应用程序

时间:2014-02-22 00:43:35

标签: android-layout user-interface android-edittext textview android

我正在尝试做一个测验应用程序,它将使用英文字母匹配telugu字母,我的UI将有一个顶部文本视图,将显示telugu字母,用户必须在编辑文本中键入相应的英文字母,并且在那个屏幕将刷新并且在那6秒之后将出现新的问题,最后我想显示统计有多少正确的答案和错误的答案,并且只显示所有错误的答案并且他们已经做出了。但是我的ui正在被攻击并且在大约60秒之后,像A->出现了。

    package vamsi.saran.koli.deepti;
    public class LetterQuiz extends Activity {
int rightAnswer = 0, wrongAnswer = 0;
TextView finalResult;
TextView top, eval;
Typeface font;
EditText answer;

String english[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
        "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
        "Y", "Z" };
String telugu[] = { "ఎ", "బి", "సి", "డి", "ఇ", "ఎఫ్", "జి", "ఎచ్", "ఐ",
        "జె", "కె", "ఎల్", "య్మ్", "యెన్", "వొ", "పి", "క్యు", "ఆర్",
        "ఎస్", "టి", "యు", "వి", "డబల్యు", "ఎక్స్", "వై", "జెడ్" };
int number;
static Random rand = new Random();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_letter_quiz);
    font = Typeface.createFromAsset(getAssets(),
            "fonts/NotoSansTelugu-Bold.ttf");

    top = (TextView) findViewById(R.id.telugu);
    eval = (TextView) findViewById(R.id.eval);
    answer = (EditText) findViewById(R.id.answer);
    finalResult = (TextView) findViewById(R.id.finale);
    finalResult.setVisibility(View.GONE);
    quiz();

}

public void quiz() {
    int wronganswers[] = new int[10];
    int j = 0;
    for (int k = 0; k < 10; k++) {
        int i;
        number = rand.nextInt(25 - 0) + 0;
        top.setTypeface(font);
        top.setTextSize(40.f);
        top.setText(telugu[number]);
        eval = (TextView) findViewById(R.id.eval);
        SystemClock.sleep(6000);
        answer = (EditText) findViewById(R.id.answer);
        String user = answer.getText().toString();
        for (i = 0; i < english.length; i++) {
            if (user.equalsIgnoreCase(english[i])) {
                break;
            }
        }
        if (i == number) {
            eval.setText("Right Answer");
            SystemClock.sleep(1000);
            rightAnswer++;
        } else {
            eval.setText("Wrong Answer");
            SystemClock.sleep(1000);
            wrongAnswer++;
            wronganswers[j] = number;
            j++;
        }
        SystemClock.sleep(2000);

    }
    finalResult
            .setText("No of right answers" + rightAnswer
                    + "\nNo of wrong answers" + wrongAnswer
                    + "\nletters to review");
    String review = "";
    for (int i = 0; i < wronganswers.length; i++)
        review = english[wronganswers[i]] + "->" + telugu[wronganswers[i]]
                + "\n";
    finalResult.setText(review);
    top.setVisibility(View.GONE);
    eval.setVisibility(View.GONE);
    answer.setVisibility(View.GONE);
    finalResult.setVisibility(View.VISIBLE);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.letter_quiz, menu);
    return true;
 }

  }


我的xml是

               <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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LetterQuiz" >

<TextView
    android:id="@+id/telugu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="100dp"
    android:layout_marginTop="19dp"
    android:text="TextView" />

<EditText
    android:id="@+id/answer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/telugu"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="71dp"
    android:ems="10"
     >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/eval"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:layout_alignRight="@+id/telugu"
    android:layout_below="@+id/answer"
    android:layout_marginRight="20dp"
    android:layout_marginTop="54dp"
    android:text="TextView" />

<TextView 

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/finale"


    />

1 个答案:

答案 0 :(得分:0)

我认为问题在于您使用wronganswers[]迭代wronganswers.length,但无论您是否犯错,它始终为10。你应该使用wrongAnswer代替。

使用它:

finalResult.setText("No of right answers" + rightAnswer
                    + "\nNo of wrong answers" + wrongAnswer
                    + "\nletters to review\n");

 String review = "";
    for (int i = 0; i < wrongAnswer; i++)
        review = english[wronganswers[i]] + "->" + telugu[wronganswers[i]] + "\n";
    finalResult.append(review);