2014-12-31 111 views
1

如何在EditText中添加文本? editText.setText刪除舊文本並在末尾寫入新的和editText.setText(editText.getText() + "my text");添加文本。 如何將文本添加到開始編輯的行中?如何在EditText中添加文本?

(很抱歉,如果有在文本中的錯誤,我住在俄羅斯,不知道多少英文)

+0

查看下面的答案@killerBLS –

回答

2

它很容易做到這一點:

int start =editText.getSelectionStart(); //Get cursor position with this function 
String str = "my text";//String you want to insert 
editText.getText().insert(start, str); //This will get the text and insert the String str at the current position. 

希望這有助於!

+0

謝謝,這是我需要的:) – KillerBLS

+0

高興地幫助你! –

0

你也許談論設置提示文本?

editText.setHint("Enter Text Here"); 

在XML

android:hint="Enter Text Here" 

如果這不是你在找什麼,那麼請alaborate問題多一點

0

要添加文本之前添加\ n。 ...

var.setText(var.getText()+「\ nnewtext」);

相關問題