0

I am working on custom keyboard where i have one problem. On key listener I need to set my current cursor position to next line. I have tried using

editText.setSelection(editText.getText().length()); 

which sets the current cursor position to end of text not to next line.

1
  • to next line or next editor? Commented Jun 17, 2013 at 13:32

3 Answers 3

2

How about:

editText.append("\n"); 

And than set the cursor to the end?

Sign up to request clarification or add additional context in comments.

3 Comments

what is it? (you can also open a new question at the same price)
as i am working on keyboard, as we know on default keyboard on device when we click any key larger image is displayed, you which is this effect..
I'm not sure I understand the question, and it doesn't seem related to this topic. Can you open a new question?
1

It's not quite clear to me, whether the insertion of a new line is desired as the enter key produces it in e.g. notepad. In that case uval's answer seems fine, besides you might want to remember the current position of the cursor before inserting:

int position = editText.getSelectionStart(); editText.getText().insert(position, "\n"); editText.setSelection(position + 1); 


Otherwise, if you just want to jump around in the text, as you can do with the arrow keys in notepad, you'll probably have to calculate the number of characters per line at the given width of your view and the size of its text and then get the number and position of the following line accordingly.

Comments

0

use

 <EditText android:id="@+id/fnameUser" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dp" android:background="@drawable/text_bar" android:hint="First Name" **android:text="@string/newline"** android:textColor="#ffffff" android:padding="5dp" /> 

where

<string name="newline">\n</string> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.