Android 使用textview显示结果
我正在android上开发一个测验应用程序,我想在其中显示正确答案(即预先存储的答案)和用户选择的答案(无论是正确的还是错误的)。 此外,我希望每次显示新问题时,单选按钮应为未选中/空 我写了下面的代码,通过它只显示正确答案和错误答案的数量。 请帮帮我Android 使用textview显示结果,android,android-intent,textview,Android,Android Intent,Textview,我正在android上开发一个测验应用程序,我想在其中显示正确答案(即预先存储的答案)和用户选择的答案(无论是正确的还是错误的)。 此外,我希望每次显示新问题时,单选按钮应为未选中/空 我写了下面的代码,通过它只显示正确答案和错误答案的数量。 请帮帮我 Computer_Test1_Activity: package com.example.owner.cybergram; import android.app.Activity; import android.con
Computer_Test1_Activity:
package com.example.owner.cybergram;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class Computer_Test1_Activity extends Activity {
TextView code;
Button btnNxt;
RadioGroup rg1;
RadioButton rb1, rb2;
String questions[] = {"1. Generating the corresponding code is known as encoding.","2.Word processing software automatically corrects spelling & grammar mistakes.","3. OBR scans a set of vertical bars of different widths for specific data","4. More pixels means sharper image.","5. E-learning softwares can reduce the use of books.","6. Inkjet printer is a non-impact printer.","7. VGA stands for Video Graphics Array.","8. A mouse is a storage device.","9. A diskette is expensive, can not be erased and cannot be reused.","10. Graphics engineers can use computers to create 3 dimensional models.","11. A series of instructions is known as ____________.","12. The programs and data that are required to be used again and again are kept in","13. Information, Electronics and Communication Technology","14. The term Bit is an acronym of","15. Numbers are stored and transmitted inside a computer in","16. Secondary memory of a computer also known as _____________.","17. Three categories of display screen technology are","18. The use of copy and paste feature in word processing is-","19. MICR stands for?","20. The 3 different type of buses used in computer are"};
String ans[] = {"True","True","True","True","True","True","True","False","False","True","Program","Secondary memory","Information, Electronics and Communication Technology","Binary digit","Binary form","Auxiliary memory","CRT, LCD & Projection displays","To avoid typing the same content again","Magnetic Ink Character Reccognition","Address bus, Data bus & Control bus"};
String opt[] = {"True", "False","True","False","True","False","True","False","True","False","True","False","True","False","True","False","True","False","True","False","Program","Software","Hard disk","Secondary memory","Information, Electric and Communication Technology","Information, Electronics and Communication Technology","Binary digit","Byte","ASCII code form","Binary form","Auxiliary memory","Special memory","CRT, LCD & Projection displays","CRT, LCD & LED","To avoid the mistakes","To avoid typing the same content again","Magnetic Ink Character Recognition","Magnetic Ink Card Reader","Address bus, Data bus & Control bus","Data bus, Control bus & Logical bus"};
int flag = 0;
public static int marks, correct, wrong;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.computertest1);
code = (TextView) findViewById(R.id.codeques);
btnNxt = (Button) findViewById(R.id.btnNxt);
rg1 = (RadioGroup) findViewById(R.id.rg1);
rb1 = (RadioButton) findViewById(R.id.rb1);
rb2 = (RadioButton) findViewById(R.id.rb2);
code.setText(questions[flag]);
rb1.setText(opt[0]);
rb2.setText(opt[1]);
/* Toast.makeText(this, "Negative Marks: " + ComputerActivity.tbflag,1000).show();*/
btnNxt.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
RadioButton uans = (RadioButton)findViewById(rg1.getCheckedRadioButtonId());
// get selected radio button from radioGroup
int selectedId = rg1 .getCheckedRadioButtonId();
// find the radio button by returned id
RadioButton rg1 = (RadioButton) findViewById(selectedId);
String ansText = uans.getText().toString();
if (ansText.equals(ans[flag]))
{
correct++;
}
else
{
wrong++;
}
flag++;
if (flag < questions.length)
{
code.setText(questions[flag]);
rb1.setText(opt[flag*2]);
rb2.setText(opt[(flag*2)+1]);
}
else
{
if (ComputerActivity.tbflag)
{
marks = correct - wrong;
}
else
{
//incase of negative marks off
marks = correct;
}
Intent n = new Intent(Computer_Test1_Activity.this,ComputerResultActivity.class);
startActivity(n);
}
}
});
}
}
请帮帮我。启动ComputerResultActivity时,您是否考虑过Intent.putExtra?我想这是完成你正在做的事情的方法。我没有理解你,你到底想说什么。sb.append(“Correct Ans:+Computer\u Test1\u Activity.Correct”);sb.追加(“\n错误的Ans:+计算机测试1\u活动。错误”);sb.追加(“\n最终分数:+计算机测试1+活动分数);这部分不会像您希望的那样工作,您应该将所有这些内容作为额外内容放在intent(intent.putExtra…)中,然后在其他活动中getIntent().getIntExtra()取消勾选/勾选复选框可以通过chkbox.toggle()完成。谢谢,这非常有用
Computer_Test1_Activity:
package com.example.owner.cybergram;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class Computer_Test1_Activity extends Activity {
TextView code;
Button btnNxt;
RadioGroup rg1;
RadioButton rb1, rb2;
String questions[] = {"1. Generating the corresponding code is known as encoding.","2.Word processing software automatically corrects spelling & grammar mistakes.","3. OBR scans a set of vertical bars of different widths for specific data","4. More pixels means sharper image.","5. E-learning softwares can reduce the use of books.","6. Inkjet printer is a non-impact printer.","7. VGA stands for Video Graphics Array.","8. A mouse is a storage device.","9. A diskette is expensive, can not be erased and cannot be reused.","10. Graphics engineers can use computers to create 3 dimensional models.","11. A series of instructions is known as ____________.","12. The programs and data that are required to be used again and again are kept in","13. Information, Electronics and Communication Technology","14. The term Bit is an acronym of","15. Numbers are stored and transmitted inside a computer in","16. Secondary memory of a computer also known as _____________.","17. Three categories of display screen technology are","18. The use of copy and paste feature in word processing is-","19. MICR stands for?","20. The 3 different type of buses used in computer are"};
String ans[] = {"True","True","True","True","True","True","True","False","False","True","Program","Secondary memory","Information, Electronics and Communication Technology","Binary digit","Binary form","Auxiliary memory","CRT, LCD & Projection displays","To avoid typing the same content again","Magnetic Ink Character Reccognition","Address bus, Data bus & Control bus"};
String opt[] = {"True", "False","True","False","True","False","True","False","True","False","True","False","True","False","True","False","True","False","True","False","Program","Software","Hard disk","Secondary memory","Information, Electric and Communication Technology","Information, Electronics and Communication Technology","Binary digit","Byte","ASCII code form","Binary form","Auxiliary memory","Special memory","CRT, LCD & Projection displays","CRT, LCD & LED","To avoid the mistakes","To avoid typing the same content again","Magnetic Ink Character Recognition","Magnetic Ink Card Reader","Address bus, Data bus & Control bus","Data bus, Control bus & Logical bus"};
int flag = 0;
public static int marks, correct, wrong;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.computertest1);
code = (TextView) findViewById(R.id.codeques);
btnNxt = (Button) findViewById(R.id.btnNxt);
rg1 = (RadioGroup) findViewById(R.id.rg1);
rb1 = (RadioButton) findViewById(R.id.rb1);
rb2 = (RadioButton) findViewById(R.id.rb2);
code.setText(questions[flag]);
rb1.setText(opt[0]);
rb2.setText(opt[1]);
/* Toast.makeText(this, "Negative Marks: " + ComputerActivity.tbflag,1000).show();*/
btnNxt.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
RadioButton uans = (RadioButton)findViewById(rg1.getCheckedRadioButtonId());
// get selected radio button from radioGroup
int selectedId = rg1 .getCheckedRadioButtonId();
// find the radio button by returned id
RadioButton rg1 = (RadioButton) findViewById(selectedId);
String ansText = uans.getText().toString();
if (ansText.equals(ans[flag]))
{
correct++;
}
else
{
wrong++;
}
flag++;
if (flag < questions.length)
{
code.setText(questions[flag]);
rb1.setText(opt[flag*2]);
rb2.setText(opt[(flag*2)+1]);
}
else
{
if (ComputerActivity.tbflag)
{
marks = correct - wrong;
}
else
{
//incase of negative marks off
marks = correct;
}
Intent n = new Intent(Computer_Test1_Activity.this,ComputerResultActivity.class);
startActivity(n);
}
}
});
}
}