每秒更改TextView文本

时间:2015-07-16 15:47:24

标签: java android textview sleep

我找不到多个TextViews的解决方案。我想在Button点击时每秒或1/2秒更改文字:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_2);

    Show = (TextView) findViewById(R.id.Show);
    Start = (Button) findViewById(R.id.Start);

    Start.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Show.setTextColor(android.graphics.Color.BLUE);
            SystemClock.sleep(1000);
            Show.setText("Example Text 1");
            SystemClock.sleep(1000);
            Show.setText("Example Text 2");
            SystemClock.sleep(300);
            Show.setText("Example Text 3");
            SystemClock.sleep(800);
            Show.setText("Example Text 4");
            SystemClock.sleep(5000);
            Show.setText("Example Text 5");
            SystemClock.sleep(1000);
            Show.setText("Example Text 6");
            SystemClock.sleep(2000);
            Show.setText("Example Text 7");
            SystemClock.sleep(100);
       }    
    });
 }

但这不会奏效。如果我点击Button没有任何反应,稍后TextView会显示示例文本7

1 个答案:

答案 0 :(得分:1)

此代码从5倒数到1(显示该值),然后写入" GO!"

{{1}}

它假设您在当前的ContentView布局中有一个名为txtCount的TextView