0

I wanna create a program has two Buttons named button1 and button2.This is block of button1 onClick method :

    public void click1(View v){
        Button b = (Button)findViewById(R.id.button2);
        b.setText("TEXT 1");
        SystemClock.sleep(500);
        b.setText("TEXT 2");

    }

but the problem is after first change of object 'b' text to "TEXT 1" , it occurs nothing and after 500 ms text of 'b' changes to "TEXT 2".

What's the problem?

How to refresh Layout views contents?

4

1 回答 1

1

而不是使用SystemClock.sleep(500);,请你Handler,你可以试试这个代码:

public void click1(View v){
                Button b = (Button)findViewById(R.id.button2);
                b.setText("TEXT 1");
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        b.setText("TEXT 2");    
                    }
                }, 500;)
                //b.forceLayout();
            }

希望这可以帮助。

于 2013-08-12T08:17:24.600 回答