Android how to combine textMultiLine and actionNext in EditText
I just want to do something VERY simple:
If I have edit text, I want the max to be 5 lines of text high in the textbox height and I was such that when the user types something and then they press Enter or Next, I create for them a new line, but first I comment on something. that is -> if I want edit text that starts with:
1.
if the user types "hello" then the edit text will look like this:
1. hi
but now if the user then accesses "Enter" / "Next" then I want the text to be:
1. hi
2.
where I automatically fill in "2." with a new line.
here's what my edit text looks like:
<EditText
android:id="@+id/something"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:inputType="textMultiLine"
android:imeOptions="actionNext"
android:text="1. "/>
and of course I provide a custom editor for this EditText setOnEditorActionListener
like:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
private int mNumberOfLines = 1;
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
mNumberOfLines++;
editText.setText(editText.getText() + "\n" + mNumberOfLines + ". ");
editText.setSelection(editText.getText().length());
return true;
}
return false;
}
});
.... Why doesn't it work? if i use text
instead textMultiLine
then editText doesn't recognize newlines. but if i use textMultiLine
then the key action for is IME_ACTION_NEXT
not recognized. WTF?
source to share
No one has answered this question yet
Check out similar questions: