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);, please youを使用する代わりに、次の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 に答える