4

I have a android.widget.EditText (in multi line read only mode) in which I display some informations (the left half):

enter image description here

From time to time additional informations are added to the end of this android.widget.EditText and then I would like to scroll to the end of the the field (perhaps only scrolling to the end if already positions at the end which I think is even more user friendly).

Surprisingly I was unable to find any information on cursor and scroll movement in android.widget.EditText.

I found this posting but i don't have a ScrollView and I wonder why would I want one as a android.widget.EditText can handle it own scolling.

Any ideas or insights? What did I miss?

Community
  • 1
  • 1
Martin
  • 11,577
  • 16
  • 80
  • 110

3 Answers3

3

If scrolling to the end is all you want then the following will do:

     this.Printout.setText ("");
     this.Printout.append (Service.Get_FP10_Printout ());

The trick here: android.widget.EditText.append will scroll to the end of the field for you. So I delete the text and then append what I want to display.

If you need any other scrolling then you need to envelop the android.widget.TextView with an android.widget.ScollView (as lumis suggested) and use the trick from Patrick.

Community
  • 1
  • 1
Martin
  • 11,577
  • 16
  • 80
  • 110
  • 1
    I wonder if it would scroll if you append just a single space or return on the text already in it? Nice thing about the scroll view is that by using a CountDownTimer and scrollTo() you can set your own speed of scrolling. – Lumis Sep 08 '11 at 10:26
  • With the other calculator (http://my.opera.com/HP-45/blog/2011/03/09/honeycomb-has-arrived) I do add single returns and yes it works as expected. This is how I found out about this behaviour in the first place. However: You then have an empty row at the end of the field. – Martin Sep 08 '11 at 11:03
  • I am curious, have you tried to append an empty string: object.append(""); – Lumis Sep 08 '11 at 12:49
  • No I did not. For me there is not difference since the FP10 Simulator keeps the text in a StringBuffer and I always need to set the text in full anyway. – Martin Sep 08 '11 at 14:56
1

You know, Casio FX602P was my very first programmable computer!

I am not sure if editView can be made to scroll on its own, but if you envelop a textView with a scrollView and disable the scroll bars you should get what you need.

One other possibility came to my mind; if you use a List instead that would allow not just to scroll but to select the line of code which one wants to edit in the display on the right...

Lumis
  • 21,517
  • 8
  • 63
  • 67
  • A List might not be as good s I want the user to be able to copy paste the result for use in other applications. So the extra scroll view might be the only option. PS: The calculator is available in the market already ;-). I am just adding the final touches for Honeycomb right now. It's GPL as well, you can look at the sources as well of you like. – Martin Sep 07 '11 at 13:46
  • It is easy to convert a list into a text, it is just one loop. Actually I would like a real thing, but it is not easy to get it on eBay, everyone wants it! – Lumis Sep 07 '11 at 14:16
  • Using a `android.widget.ScollView`does work but I found an even easier trick: http://stackoverflow.com/questions/7333778/how-tot-scroll-to-end-of-an-android-textview/7345050#7345050 – Martin Sep 08 '11 at 08:17
0

To accomplish this you must wrap the EditText in a ScrollView and control it through it's parent. It was previously possible to simply use EditText.append to accomplish this as indicated by one of the answers append here. However google has made all standard EditText's AppCompat now which has changed the behavior of the append function, it no longer scrolls to the end.

I found out the hard way as my app's functionality changed after a compile with the newer API.

Community
  • 1
  • 1
user3259330
  • 448
  • 6
  • 9