我想根据等级收集不同活动的分数和完成时间。我也想重置测验。每个级别都有5个问题:我希望我的代码应该看起来像附加图像。目前我能够改变5次问题。但不知道如何更新关卡和得分以及计时器,然后生成显示结果的文件,如级别,分数,时间
public class ArrayAct extends Activity {
private Button doneBtn;
private EditText text;
private TextView textView;
private String [] mArray;
private String [] mArray1;
private int generatedIndex;
private HashMap<String,String> questionMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.arrayact);
textView = (TextView)findViewById(R.id.txtView);
doneBtn = (Button)findViewById(R.id.doneBtn);
text = (EditText)findViewById(R.id.txtFld);
mArray = getResources().getStringArray(R.array.Answers);
mArray1 = getResources().getStringArray(R.array.Questions);
questionMap = new HashMap<String, String>();
doneBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(doneBtn.getText().equals("Close")){
finish();
}else{
if (mArray[generatedIndex].equals(text.getText().toString())){
Toast.makeText(getApplicationContext(), "Correct!", Toast.LENGTH_SHORT).show();
if(questionMap.size()==3){
Toast.makeText(getApplicationContext(), "Your test is over!!!", Toast.LENGTH_SHORT).show();
doneBtn.setText("Close");
}else{
text.setText("");
prepareQuestion();
}
}else{
Toast.makeText(getApplicationContext(), "Incorrect.Please try again.", Toast.LENGTH_SHORT).show();
}
}
}
});
prepareQuestion();
}
private void prepareQuestion(){
Random random = new Random();
do{
generatedIndex = random.nextInt(mArray1.length);
}while(questionMap.containsKey(String.valueOf(generatedIndex)));
questionMap.put(String.valueOf(generatedIndex),"");
textView.setText(mArray1[generatedIndex]);
}
}
public class ArrayAct extends Activity {
private Button doneBtn;
private EditText text;
private TextView textView;
private String [] mArray;
private String [] mArray1;
private int generatedIndex;
private HashMap<String,String> questionMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.arrayact);
textView = (TextView)findViewById(R.id.txtView);
doneBtn = (Button)findViewById(R.id.doneBtn);
text = (EditText)findViewById(R.id.txtFld);
mArray = getResources().getStringArray(R.array.Answers);
mArray1 = getResources().getStringArray(R.array.Questions);
questionMap = new HashMap<String, String>();
doneBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(doneBtn.getText().equals("Close")){
finish();
}else{
if (mArray[generatedIndex].equals(text.getText().toString())){
Toast.makeText(getApplicationContext(), "Correct!", Toast.LENGTH_SHORT).show();
if(questionMap.size()==3){
Toast.makeText(getApplicationContext(), "Your test is over!!!", Toast.LENGTH_SHORT).show();
doneBtn.setText("Close");
}else{
text.setText("");
prepareQuestion();
}
}else{
Toast.makeText(getApplicationContext(), "Incorrect.Please try again.", Toast.LENGTH_SHORT).show();
}
}
}
});
prepareQuestion();
}
private void prepareQuestion(){
Random random = new Random();
do{
generatedIndex = random.nextInt(mArray1.length);
}while(questionMap.containsKey(String.valueOf(generatedIndex)));
questionMap.put(String.valueOf(generatedIndex),"");
textView.setText(mArray1[generatedIndex]);
}
}
答案 0 :(得分:0)
您可以使用android中的CountDownTimer
来计算1分钟。像这样:
new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("time is up!");
}
}.start();
最后(finish
)你可以随心所欲。例如,更改片段,或设置新问题,或完成当前活动并开始新活动。