Reading and Writing to EditText
What is the best way to read text from EditText into code and write some text from code to EditText?
Sorry I have not a TextView but an EditText
Hello to all
I am new to android, I want to write automatically from code to EditText and read in code from EditText
What is the best way to do this.
source to share
Java classes typically expose readable attributes using a method get*
and writeable attributes using a method set*
. In case a EditText
it is:
getText
and
setText
see here and here (they are inherited from TextView
)
Note: Scroll a little. You will see that they are defined several times. With different parameters. Choose the one you need.
A simple example. Suppose you have a TextView with id myTextField
:
EditText myText = (EditText) this.findViewById(R.id.myTextField);
// Setting the text:
myText.setText( "Hello World!" );
// "Reading" the text (printing it to stdout):
System.out.println( myText.getText() );
source to share