obrien
obrien

Reputation: 496

How to refresh view in android

I have a layout which contains button and textView with visibility="gone". This layout is child of scrollView. When button has been pressed the textView visibility is set to "visible" but it overflows the screen (this is why it is in scrollView).

My problem is that I'd like to automatically scroll to the end of the page.

So I've tried:

mySchrollView.fullScroll(View.FOCUS_DOWN);

But unfortunately it doesn't work. It seems that layout will be updated after end of the onClick method (and indeed if I call this method again (new click) it is working).

So I need to refresh the layout or screen before calling fullScroll(...); I tried refreshDrawableState() or forceLayout() but it haven't worked either.

Do you have any idea how to solve it?

Thanks a lot

Upvotes: 1

Views: 3323

Answers (5)

Pratik Bhat
Pratik Bhat

Reputation: 7614

tried using recreate() which is available since api 11 ??

Upvotes: 0

Jave
Jave

Reputation: 31846

you can do:

yourText.setVisibility(View.VISIBLE);
schrollView.post(new Runnable{
    @Override
    public void run(){
        schrollView.fullScroll(View.FOCUS_DOWN);
    }
}

And the fullScroll() will be handled when everything else that is already scheduled (e.g. the layout) is completed.
If this for some reason won't work, you can use postDelayed(runnable, 100); (use the same runnable as in the above example), and the view will scroll after 100 milliseconds.

Upvotes: 2

Saurabh Verma
Saurabh Verma

Reputation: 6728

You can use the method schrollView.smoothScrollTo(x, y). So, in your case the code will look like :

schrollView.smoothScrollTo(0, deviceHeight);

Upvotes: 0

cheng81
cheng81

Reputation: 2434

Have you tried calling "schrollView.requestLayout()" or "schrollView.invalidate()"? (btw. shouldn't it be called "scrollView"?)

Upvotes: 0

Vishal Pawar
Vishal Pawar

Reputation: 4340

have you tried requestLayout()

Upvotes: 1

Related Questions