zoukankan      html  css  js  c++  java
  • 实现文字隔3秒自动循环变化

    xml布局文件

    <TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textSize="25sp"
    android:text="nihaoma,wo yidain dou bu hao"
    />

    MainActivity页面:

    public class MainActivity extends Activity implements Runnable{
    private TextView text;
    private Handler handler;
    private String[] title=new String[]{"000","111","222","333"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    text=(TextView)findViewById(R.id.text);
    Thread t=new Thread(this);
    t.start();
    handler=new Handler(){
    public void handleMessage(Message msg) {
    if (msg.what==0x101) {
    text.setText(msg.getData().getString("title"));

    }
    };
    };

    }
    @Override
    public void run() {
    // TODO Auto-generated method stub
    int index=0;
    while (!Thread.currentThread().isInterrupted()) {
    if (index<3) {
    index++;
    }else{
    index=0;
    }
    Message m=handler.obtainMessage();
    m.arg1=index;
    Bundle bundle=new Bundle();
    m.what=0x101;
    bundle.putString("title", title[index]);
    m.setData(bundle);
    handler.sendMessage(m);
    try {
    Thread.sleep(3000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    }
    }

  • 相关阅读:
    冒泡排序&快速排序
    1252. Cells with Odd Values in a Matrix
    位运算小结
    832. Flipping an Image
    1812. Determine Color of a Chessboard Square
    10、属性、构造函数与析构函数
    09、封装与类成员
    07、面向对象简介
    06、C#异常处理
    03、运算符
  • 原文地址:https://www.cnblogs.com/xiaoshumiao/p/6834711.html
Copyright © 2011-2022 走看看