I need to read a user input in android to process it later.
How can I do this?
In iPhone SDK I\'d do something like this:
-(IBAction)command {
Put this in you code:
final EditText edittext = (EditText) findViewById(R.id.edittext);
And this is the textbox, or whatever:
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
And something like this to get the text of it:
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
Put an EditText
in your UI, and call getText().toString()
on it when you need the value that the user typed in.