• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Text box question

Iguy29

Lurker
Hi, I was just working on an app, and I noticed that I could use the Edit Text in the layout to create a place for the user to input text. There is only one problem, how would you access that text and put it into, say a string? Thanks in advance!
 
In your onCreate() method, capture the EditText object, like so:
Code:
final EditText edit = (EditText)findViewById(R.id.edit_text_name_in_XML_file);
Then, you can use the methods of the EditText object to get/set its contents, like so:
Code:
edit.setText("Hello!");
String sayWhat = edit.getText();
It's that easy!

--Boogs
 
Back
Top Bottom