1

I want create simple calculator for android, and having problem with displaying long equations. Everything is OK (one line, horizontal scrolling), but I don't see end of line (always see start of line). Would it be possible to scroll it automatically to the latest character?

Example:

Hello there
...lo there
   --------

-

<EditText
        android:id="@+id/etDisplay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:clickable="false"
        android:cursorVisible="false"
        android:ems="10"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="right"
        android:textSize="15sp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:ellipsize="end"
        android:hint="0." />

Image: SimpleCalc image

Cœur
  • 37,241
  • 25
  • 195
  • 267
Matjaž
  • 2,096
  • 3
  • 35
  • 55

2 Answers2

1

Try this one:

EditText editText = (EditText) findViewById(R.id.editText1);
editText.setSelection(editText.getText().length());
luwionline
  • 186
  • 2
  • 12
  • Thank you, it works perfectly :D only code is much more longer. If is there any other way to set this in xml please let me know. – Matjaž Jan 25 '14 at 18:02
0

The "official" way of doing that is (as suggested in the comments), via the ellipsize attribute set to end. If it's not working, it might be due this attribute is a bit tricky, meaning that it has some circumstances to be happening in order to work (like for example, singleLine=true).

You might want to see this, it helped me when I had this issue.

Community
  • 1
  • 1
nKn
  • 13,691
  • 9
  • 45
  • 62