开发者

How can i get text from text field and place text in another text field in android

Hi I am new to android, How can i get text from a text field and store into variable and how can i place text in a text field. Whati mean is, in C# or Flex or other languages we have functions or properties like if there is some text field txtName, and we do txtName.text or txtName.getText(), it returns text, and if we do like txtName.text ="abc", it assigns a value to it, but i have not found any thing like th开发者_Python百科at in android yet, please help me.

Regards Atif


Use getText() and setText() method of TextView. For example:

TextView tf=new TextView(this);
 tf.setText("Hello");
 String s=(String) tf.getText();


assuming in your XML layout your EditText has the id text you can get it by

final EditText text = (EditText) findViewById(R.id.text);
String textInEditText = text.getText().toString();

or you can set it by:

text.setText("Some text");

You can find more information about EditText and general Android Development (e.g. what is a layout?) in the normal guides.


You should first get ids for the EditTexts:

 EditText et1=(EditText) findViewById(R.id.edit_text1);  //replace edit_text1 with your id
 EditText et2=(EditText) findViewById(R.id.edit_text2);  //replace edit_text2 with your id
 et2.setText(et1.getText());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜