10

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?

rala
  • 895
  • 2
  • 18
  • 43

3 Answers3

9

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

Sanjeev
  • 4,255
  • 3
  • 28
  • 37
CompEng
  • 7,161
  • 16
  • 68
  • 122
  • Did you use if(cm.getActiveNetworkInfo. Gettext() >0) then Set cursor – CompEng Mar 23 '14 at 08:18
  • I even tried it on 4.0.3 - there it works but not on 4.1.2 (S3 Stock & PA) – rala Mar 23 '14 at 08:24
  • I mean when the Set selection method did you use the if Control and what is the error when you use setselection – CompEng Mar 23 '14 at 08:25
  • I edit my answer, if it gives error please show error – CompEng Mar 23 '14 at 08:29
  • So if it is Empty the cursor is beginning so what is the problem – CompEng Mar 23 '14 at 08:37
  • see at the picture, that's an empty edittext - the cursor is at the start of the hint in 4.1.2 (not in 4.0.3...) - and for me, it looks strange... - it should be like 4.0.3 at the end (if gravity is right) – rala Mar 23 '14 at 08:39
  • yes, and in the autocompletetextview its the same (subnetmask) – rala Mar 23 '14 at 08:43
  • is there - I just post one of them – rala Mar 23 '14 at 08:51
  • this is only if the text is longer then the view, isn't it? – rala Mar 23 '14 at 08:55
  • Did you try android:ellipsize="end"? – CompEng Mar 23 '14 at 08:56
  • I dont understand you can Set your own paddingleft as you need and when à Text Enter you can Set paddingleft to 0 programmtically – CompEng Mar 23 '14 at 09:13
  • Is it Works? Can you check – CompEng Mar 23 '14 at 09:21
  • no change; I mean padding is for the whole edittext -> the start from the left and not for the cursor; I've a relative layout... – rala Mar 23 '14 at 09:22
  • 1
    So there is one way I think, instead of hint you settext as email and give text Color it looks as hint and the cursor is in the end, and when à Text Enter you should delete Text firstly and Change text Color, this solve your problem – CompEng Mar 23 '14 at 09:32
  • Sorry, what you mean when you say Keyboard – CompEng Mar 23 '14 at 09:57
  • if I set it to keyboard I coild also type letters - without them I could only write what I need (numbers, dots and slash) – rala Mar 23 '14 at 10:01
  • You can Change it programmatically like this **http://stackoverflow.com/questions/9892617/programmatically-change-input-type-of-the-edittext-from-password-to-normal-vic** or you should use keylistener to abort chars which you dont want but I Select first one – CompEng Mar 23 '14 at 10:04
1

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

Pang
  • 9,564
  • 146
  • 81
  • 122
Double.C
  • 11
  • 1
-2

This works for me.

textview.setTextDirection(View.TEXT_DIRECTION_RTL);

Jakob
  • 37
  • 8