Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the cursor to the right (EditText)?

How to set the cursor to the right with right align and hint text?
Is it possible?

I have a AutoCompleteTextView and a EditText with Text right align and an hint text. Now if one of them is focused the curser is before the hint and not at the end of the line. So it looks like now it's bad...

I've also tried to set the cursor position, but it didn't help of course.

<AutoCompleteTextView
    android:id="@+id/input_snm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/input_ipAdresse"
    android:ems="10"
    android:gravity="right"
    android:hint="@string/input_snm"
    android:imeActionLabel="@string/Button_berechnen"
    android:imeOptions="actionDone|flagNoExtractUi"
    android:inputType="phone"
    android:paddingRight="@dimen/padding_small"
    android:textSize="@dimen/fontsize_medium" />


Image: EditText
Image: EditText

Ok, I think it's an System error, isn't it?

like image 326
rala Avatar asked Mar 21 '14 15:03

rala


People also ask

How do I change the cursor position in EditText?

Say in your xml's edittext section, add android:paddingLeft="100dp" This will move your start position of cursor 100dp right from left end. Same way, you can use android:paddingRight="100dp" This will move your end position of cursor 100dp left from right end.

Which method is used to set the EditText?

In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.

How do you center text in EditText?

Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.


2 Answers

Set the android:Theme.Light style on the activity (theme) and android:gravity="right".

like image 180
Double.C Avatar answered Oct 10 '22 20:10

Double.C


You can use like this:

if (your_edittext.getText().length() > 0 ) {
    your_edittext.setSelection(your_edittext.getText().length());
}

Can you add this line to your EditText xml

android:gravity="right"
android:ellipsize="end"
android:paddingLeft="10dp"//you set this as you need

But when any Text writing you should set the paddingleft to zero

you should use this on addTextChangedListener

like image 45
Ersin Gülbahar Avatar answered Oct 10 '22 19:10

Ersin Gülbahar