Java 正在尝试将字符串值还原到textview中
我对android studio的编程非常陌生,似乎无法让我的应用程序将意图值还原到textview中 我有一个提问活动,向用户询问一些问题,这些问题使用是/否单选按钮回答。从这里已经进行了高级诊断,因此诊断将存储在“问题”活动中的“storeintent()”方法中。问题在于,当使用“restoreintents()”方法将意图调用到answers活动中时,textview中不会显示任何内容 以下是问题活动(答案已存储在其中,请查看所做的评论): 以下是“回答”活动(诊断是通过调用意图来检索的,但不是,请参考所做的评论):Java 正在尝试将字符串值还原到textview中,java,android,Java,Android,我对android studio的编程非常陌生,似乎无法让我的应用程序将意图值还原到textview中 我有一个提问活动,向用户询问一些问题,这些问题使用是/否单选按钮回答。从这里已经进行了高级诊断,因此诊断将存储在“问题”活动中的“storeintent()”方法中。问题在于,当使用“restoreintents()”方法将意图调用到answers活动中时,textview中不会显示任何内容 以下是问题活动(答案已存储在其中,请查看所做的评论): 以下是“回答”活动(诊断是通过调用意图来检索的
我们将非常感谢您的帮助 为什么不使用intent.putExtra(key,value),然后在目标活动中获取这些发送的信息,并使用getExtra(key)函数获取它们。 您可以这样做:
Intent i = new Intent(context, MyActivity.class);
String value = "some string";
i.putExtra("KEY_STRING", value );
并在MyActivity中获得它:
Bundle bundle = getIntent().getExtras();
if(bundle.getString("KEY_STRING")!= null) {
String str = intent.getStringExtra("KEY_STRING");
}
您忘记将值传递给answers类,请替换问题类中的以下代码
if (shouldStartNextActivity){
Intent intent = new Intent(this, answers.class);
intent.putExtra("key", value);
startActivity(intent);
} else{
Toast.makeText(getBaseContext(), "Please answer all the questions for an accurate diagnosis", Toast.LENGTH_LONG).show();
}
同样的,你们也需要在课堂上增加额外的内容
public void reset() {
Intent intent = new Intent(this, Questions.class);
intent.putExtra("key", textView.getText());
startActivity(intent);
}
您忘记在
opendiagnosis()
方法中向Intent添加额外的内容
按以下方式更改代码:
public void opendiagnosis() {
// for all pairs: one of each pair has to be checked
boolean shouldStartNextActivity = (radioButton.isChecked() || radioButton2.isChecked())
&& (radioButton3.isChecked() || radioButton4.isChecked()) && (radioButton5.isChecked() || radioButton6.isChecked())
&& (radioButton7.isChecked() || radioButton8.isChecked())&& (radioButton9.isChecked() || radioButton10.isChecked())
&& (radioButton11.isChecked() || radioButton12.isChecked())&& (radioButton13.isChecked() || radioButton14.isChecked())
&& (radioButton15.isChecked() || radioButton16.isChecked())&& (radioButton17.isChecked() || radioButton18.isChecked());
if (shouldStartNextActivity){
String value="Android Studio Is TERRIBLE";
Intent intent = new Intent(this, answers.class);
intent.putExtra("key",value);
startActivity(intent);
} else{
Toast.makeText(getBaseContext(), "Please answer all the questions for an accurate
diagnosis", Toast.LENGTH_LONG).show();
}
}
如何调用“我的活动”部分中的字符串值?谢谢你这么多的帮助far@DaMafiaGamer我编辑了答案。如果blockIt表示无法解析符号值,那么您可以看到如何将字符串放入,我做错了什么?例如,在answers类intent.putExtra(“key”,textView.getText())中,值是textView.getText(),值是textView.getText()。好的,刚刚解决了,应用程序崩溃了。看来我需要另找方法了。谢谢你的帮助。
public void reset() {
Intent intent = new Intent(this, Questions.class);
intent.putExtra("key", textView.getText());
startActivity(intent);
}
public void opendiagnosis() {
// for all pairs: one of each pair has to be checked
boolean shouldStartNextActivity = (radioButton.isChecked() || radioButton2.isChecked())
&& (radioButton3.isChecked() || radioButton4.isChecked()) && (radioButton5.isChecked() || radioButton6.isChecked())
&& (radioButton7.isChecked() || radioButton8.isChecked())&& (radioButton9.isChecked() || radioButton10.isChecked())
&& (radioButton11.isChecked() || radioButton12.isChecked())&& (radioButton13.isChecked() || radioButton14.isChecked())
&& (radioButton15.isChecked() || radioButton16.isChecked())&& (radioButton17.isChecked() || radioButton18.isChecked());
if (shouldStartNextActivity){
String value="Android Studio Is TERRIBLE";
Intent intent = new Intent(this, answers.class);
intent.putExtra("key",value);
startActivity(intent);
} else{
Toast.makeText(getBaseContext(), "Please answer all the questions for an accurate
diagnosis", Toast.LENGTH_LONG).show();
}
}