I am a new Android dev with a potentially dumb question.
In my activity create I want to make a popup dialogue box to prompt for user input. I then want to take the that input and save it as a global variable for later use. Currently I have
public class MgenActivity extends Activity {
// Instance Variables
String ip = "";
/**
* On Create
*/
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
String box = dialogBoxStart();
this.ip = box;
//more code
}
public String dialogBoxStart()
{
String returned = "";
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("MGEN Setup");
alert.setMessage("Please enter the MGEN IP address such as \n 9.42.68.69");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
//send user input to global?
//this doesnt work: this.ip = input.getText().toString();
}
};
alert.setPositiveButton("Ok", listener);
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
returned = input.getText().toString();
alert.show();
return returned;
}
The problem is that my EditText 'input' is not saving the user input so I cannot save it outwards. As well, I cannot talk to my outside variables from within my onClick method.
So TLDR: How do you save input from a dialogue box?