Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return a String value to another class in regards to editText
    text
    copied!<p>I am trying to display a textValue inserted by the user from the main class to another class/window. </p> <p>On my main class I made this method </p> <pre><code>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; } </code></pre> <p>which works </p> <p>but this </p> <pre><code>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; } </code></pre> <p>completely crashes the app. </p> <p>Here's my other class of which I'm going to display the choice. </p> <pre><code>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); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload