Given:
The user enters the text (a couple of letters or 50 lines) into EditText, and for each line a prefix is automatically added in the form of some character, for example, "*".
Example:
line 1
line two
Given:
The user enters the text (a couple of letters or 50 lines) into EditText, and for each line a prefix is automatically added in the form of some character, for example, "*".
Example:
line 1
line two
I don’t know if I wrote it correctly, but I need to check) Try hanging this logic on a button.
editText.post(new Runnable() { @Override public void run() { int lineCount = editText.getLineCount(); String line; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < lineCount; i++) { int startPos = editText.getLayout().getLineStart(i); int endPos = editText.getLayout().getLineEnd(i); line = editText.getText().toString().substring(startPos, endPos); stringBuilder.append("*").append(line); stringBuilder.append("\n"); } editText.setText(stringBuilder.toString()); } });
Source: https://ru.stackoverflow.com/questions/505008/
All Articles