1

i am working on a android application in which text is entered by Button.Pressing that button will create a string and that string will be displayed on the textView, If the is Button is pressed again then the created string will be added to the string on textView ,in case the button is pressed many times, a long string is created which cant be shown in textview due to single line.only the beginning strings will be shown.so my question is how to make disappear old rather than disappearing of new text in single line textView???

i got the solution to some extent in which i am able to shift the older text with new text when it becomes big for screen.but how should i scroll back to that older text?? help me out guys

Ajay Chauhan
  • 1,471
  • 4
  • 17
  • 37
  • share the code you are using to try to achieve this. – kandroidj Oct 05 '16 at 14:44
  • is there,s a xml way to do this......i alread used textDirection="anyRtl",gravity but not working – Ajay Chauhan Oct 05 '16 at 14:48
  • you mean you need to replace the text inside the `TextView` ? – Sakchham Oct 05 '16 at 14:50
  • `is there,s a xml way to do this...` I guess not, you can use loop and within that loop replace old text`s first character with the new one than second old with the new one and so on. – Bob Oct 05 '16 at 14:50
  • I am asking what is the required functionality ? – Sakchham Oct 05 '16 at 14:52
  • no,i didnt mean to replace the textview.i want to diappear my old text like the way happens in the textview when we enter a string of size more than the size of the screen.but rather den hiding my end part of the string i want to hide beginning part of the string... – Ajay Chauhan Oct 05 '16 at 14:55
  • well required functionality will be an array or string to store old text and a string with the new text. Than find the part in the old string you would like to remove than copy old string without removed part to a buff string and append the sting with the new text – Bob Oct 05 '16 at 14:56

2 Answers2

2

you can use android:ellipsize="start"

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="start"
        android:maxLines="1"
        android:text="Hello World! This is a really long string on a single line meant to truncate in the beginning with an ellipse." />

This however, will not scroll. enter image description here

kandroidj
  • 13,784
  • 5
  • 64
  • 76
  • how to get the same functionality with the scroll view?? – Ajay Chauhan Oct 05 '16 at 15:05
  • i just want to see my whole string in one go by displaying latest text entered??is there any way to achieve it?? – Ajay Chauhan Oct 05 '16 at 15:07
  • @AjayChauhan unfortunately I am not really sure what your ask is. If you explain more clearly i can help, otherwise i can't guess at what i Think you are asking – kandroidj Oct 05 '16 at 15:13
  • the solution provided by you is working......but what if we want to scroll that textview to view whole string?? – Ajay Chauhan Oct 05 '16 at 15:18
  • @AjayChauhan that will require some custom code, basically you can create your own MovementMethod or subclass TextView and customize the drawing of the view to use ellips and then write an OnTouchListener for that subclass – kandroidj Oct 05 '16 at 15:34
  • just checked again, your solution is not working at all....it is displaying only the beginning string with three dots – Ajay Chauhan Oct 05 '16 at 15:44
  • can u provide me some code...i am new to android...dont know how to do that – Ajay Chauhan Oct 05 '16 at 15:45
0

After googling for hours....i came up with a result....

TextView mTextView;

Inside onCreate()

mTextViewT.setHorizontallyScrolling(true);
mTextViewT.setSingleLine(true);
mTextViewT.setInputType(InputType.TYPE_CLASS_NUMBER);
Ajay Chauhan
  • 1,471
  • 4
  • 17
  • 37
  • by using this code,i am able to shift the older text out of screen by entering new text .But still my problem is nt finished yet....i dont how to scroll back to my older text....any suggestion guys?? – Ajay Chauhan Oct 06 '16 at 08:05