Skip to content Skip to sidebar Skip to footer

Scrolling EditText On ScrollView Programmatically

I am trying to make a non-editable EditText that is placed in a ScrollView and scrolling is controlled programmatically (when a left/right fling is detected). Ok, here's my simple

Solution 1:

"3. programmatically scroll the EditText, it doesnt' work"

Post a Runnable with scrolling code to ScrollView instead of calling scrolling methods directly.

post (Runnable action)

Causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread.

from: ScrollView and programmatically scrolling

Lance Nanek

There are past threads on this you can dig up. Basically you have to give the ScrollView a chance to realize it has had stuff added to it. For example:
scroll.post(new Runnable() {
public void run() {
scroll.fullScroll(ScrollView.FOCUS_DOWN); } });


Solution 2:

Add below lines to xml edittext control,

android:scrollbars="vertical" android:fadeScrollbars="false"

and then add this liens to coding

"EditText Control Object".setMovementMethod(new ScrollingMovementMethod());

Solution 3:

Its late but may help some one with this issue.. It takes around 200 miniseconds to add the last element and update it for a scrollView so this will surely work.

void scrollDown()
{
    Thread scrollThread = new Thread(){
        public void run(){
            try {
                sleep(200);
                ChatActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        myScrollView.fullScroll(View.FOCUS_DOWN);
                    }    
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    scrollThread.start();
}

Just call scrollDown(); after adding element to scrollView.


Post a Comment for "Scrolling EditText On ScrollView Programmatically"