我试图让用户在EditText中输入文本,因此我获得了新文本并检测到了新行,但我想在每个新行的开头添加一个文本。如何做到这一点?
Ibold.addTextChangedListener( new TextWatcher(){
@Override
public void onTextChanged( CharSequence txt, int start, int before, int count ) {
if (-1 != bold.indexOf("\n") ){
//here I detected new line
}
}
答案 0 :(得分:0)
你可以试试这个:
Ibold.addTextChangedListener( new TextWatcher(){
@Override
public void onTextChanged( CharSequence txt, int start, int before, int count ) {
if (-1 != bold.indexOf("\n") ){
//here I detected new line
String editTextContent = Ibold.getText().toString();
editTextContent += "ADD YOUR TEXT HERE, IT WILL BE INSERTED AFTER THE LAST LINE BREAK";
Ibold.setText(editTextContent);
}
}