Rob
Rob

Reputation: 1152

ScrollView FOCUS_DOWN, not quite there yet

I apologize for this, and I am sure it's a very rookie question... but I am still trying to grasp java and how everything works (I'm surprised I made it this far.)

I have a TextView inside of a ScrollView and I am trying to get it to focus on the bottom entry each time a new entry is added.

I have this in the code:

                getScrollView().post (new Runnable() {

                @Override
                public void run() {
                    getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
                }
            });

that is inside the

    public void onClick(View src) {

    switch(src.getId()){
    case R.id.buttonOk:

(So that when I click ok, it will focus to the bottom.)

now.. I am getting this error: The method getScrollView() is undefined for the type

do i need to call out the name of the scroll view within that first set of code, android:id="@+id/scrollView1"

Again, I am sorry I am so confused on this. I am obviously not getting something right here. Any help is greatly appreciated.

Thanks

Upvotes: 0

Views: 2707

Answers (2)

Harshid Vasoya
Harshid Vasoya

Reputation: 5721

you can used this.

     scrollview=((ScrollView) findViewById(R.id.scrollview));        
     scrollview.post(new Runnable() {
            @Override
            public void run() {
                scrollview.fullScroll(ScrollView.FOCUS_DOWN);
            }
        });

Upvotes: 4

Christopher Souvey
Christopher Souvey

Reputation: 2910

A couple things:

  1. To get access to the view from code, you use (ScrollView)findViewById(R.id.scrollView1) -- getScrollView() doesn't exist, though you can write it using the command I described.
  2. Based on what it sounds like you're trying to do, you might want to look into ListView instead (rather than appending lines to a TextView).

Upvotes: 0

Related Questions