我正在尝试将用户从主类插入到另一个类/窗口的 textValue 显示出来。
在我的主课上,我做了这个方法
public String retChoice()
{
choices[0] ="sasda"; //editText.getText().toString(); //pass from click button to method.
choices[1] ="asdsa";//editText2.getText().toString();
choices[2] = "asdsads"; //editText3.getText().toString();
finalChoice =rand.nextInt(2);
displayChoice = choices[finalChoice];
return displayChoice;
}
哪个有效
但是这个
public String retChoice()
{
choices[0] = editText.getText().toString(); //pass from click button to method.
choices[1] = editText2.getText().toString();
choices[2] = editText3.getText().toString();
finalChoice =rand.nextInt(2);
displayChoice = choices[finalChoice];
return displayChoice;
}
完全使应用程序崩溃。
这是我将展示选择的另一类。
public class resultScreen extends Activity {
MainActivity ma = new MainActivity();
//Method supposedly retrieves the string data from MainActivity Class but somehow displayed null instead.
//Find a way to keep the string variable when transfering from one class to another class.
String finalResult = ma.retChoice();
public void onCreate(Bundle resultScreen){
super.onCreate(resultScreen);
setContentView(R.layout.resultscreen);
//ma.displayChoice.toString();
String str = finalResult;
TextView text = (TextView) findViewById(R.id.textView1);
text.setText(str);
}