So I got a copy of the 25 hour android book and I started trying to
port a program that was written in D and ran on the command line into
a simple android program.  First I ported it to command line Java and
put it into a single class.  Then I "extended" the class so as to port
it to Android.  The approach has actually been successful - I used a
single overloaded routine for my line output in the Java port, and
have pushed the output into a textview in the overload, overriding
that routine to do so.

In another place in this group, someone posted a comment under
"Extremely frustrating" where they wanted to get a reply on how to get
a textview within a scrollview to scroll to the bottom automatically.

I wanted to do the same thing, but in a scrollable text view.  I
adapted the answer given and thought it was worth posting since I
found this hard to figure out as a new-to-android programmer and I
could not find a example when I googled - everyone referred to the
textview inside the scrollview.  Many people prefer that setup and I
have read about it and am not sure why.  Can someone explain?  It just
seems that it is an extra control, I presume more overhead, although
it just may not matter.

To make the text view scrollable:

        tv.setScroller(new Scroller(edittext.getContext()));
        tv.setMovementMethod(new ScrollingMovementMethod());

and I set the android:MaxLines property to a large value, 1024, and I
also set android:scrollbarAlwaysDrawVerticalTrack="true" although that
seems to do nothing regarding allowing the scroll bar to appear.  That
may be because with 1024 as max the bar is too small?

Elsewhere, I put text into textbuffer, a char array, and I want to
display the end:

        tv.setLines(outputwindow.getLineCount() + newlinecount);  // count
newlines and use setLines to update
        tv.setText(textbuffer,0,textused);
        tv.post(new Runnable() {
            public void run() {
                outputwindow.scrollTo(0, View.FOCUS_DOWN);
            }
        });

I honestly have no idea if I'm doing the right thing with linecount,
but it seems to work.  This allows my output to appear incrementally,
more or less.  I think that I am not understanding something about the
interaction between linecount and maxlinecount and so forth. I've read
the reference doc and don't understand it quite. Maybe someone who
actually understands this stuff can help.

I have a routine that does a lot of calculation, and on the emulator,
at least, it seems to time out if given a too-large space to iterate
over.  I presume that putting out some output in this manner will
allow the calculation to continue without the timeout (No - you have
to move the calculation to a separate thread).  Hmmm...I googled for
how to start a calculation thread and and found a clear example of how
to start such a thread (in the FAQ), and I am transmitting the output
back to the main thread to be displayed. It was surprisingly easy to
do and the example was clear.

Any suggestions as to the textview vs. scrollview containing a
textview? And why someone would prefer one or the other?  And is there
a pointer to an explanation of the various lines stuff for the
textview?  I looked for this and I might just be shortsighted or tired
but I don't get it.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to