SoFunction
Updated on 2025-03-08

Refresh scrollview example in Activity (local ui refresh)


package ;

import ;
import ;
import ;
import ;
import ;
import ;

public class MainActivity extends Activity implements {
private Button btnExit;
private TextView text;
private ScrollView scroll;
private boolean bool = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView(.activity_main);
    btnExit = (Button) findViewById();
    text    = (TextView) findViewById();
    scroll  = (ScrollView) findViewById();
    (this);
//Open a child thread in the main thread main to refresh the local ScrollView
    new Thread(new RefreshThread()).start();   
}

@Override
public void onClick(View v) {
    switch(()) {
    case :
        finish();
        break;
    }

}  
public class RefreshThread implements Runnable{

    @Override
    public void run() {
        while(bool) {
            try {
(5000);//Refresh every five seconds
            } catch (InterruptedException e) {
                ();
            }
            synchronized (this) {
//Refresh with post method
                (new Runnable() {                 
                    @Override
                    public void run() {
                        ("Hello World...n");
                    }
                });
            }
        }

    }      
}  
@Override
protected void onDestroy(){
    ();
    bool = false;
}
}