tags:

views:

165

answers:

2

Hi all

I am a new to android I wish to write automatically from code to TextViw and read in code from TextView

What is the best way to do it.

A: 

Sorry I have ment not the TextView but the EditText

Hi all

I am a new to android I wish to write automatically from code to EditText and read in code from EditText

What is the best way to do it.

ilana
Great... now I put the wrong answer... please, as Jurily mentioned above, edit your original question and delete this answer.
exhuma
Okay. I updated my answer to reflect the correct class.
exhuma
A: 

Java classes usually expose readable attributes with a get* method, and writable attributes with a set* method. In the case of a EditText these are:

getText

and

setText

see here and here (they are inherited from TextView)

Note: Scroll around a bit. You will see that they are defined multiple time. With different parameters. Pick the one you need.

A simple example. Let's assume you have a TextView with the 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() );
exhuma