• 实现文字隔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();
    }

    }
    }
    }

  • 相关阅读:
    PHP双向队列
    [转]数据库查询的3个优化方法
    MySQL性能测试工具 mysqlslap
    PHP各种魔术方法测试
    VBA中级班课时3小结
    VBA中级班课时1小结
    执行cmd并返回程序结果
    Update Dataset data back to Database
    终于会用c#中的delegate(委托)和event(事件)了
    c#: Enqueued event for Queue<T>
  • 原文地址:https://www.cnblogs.com/xiaoshumiao/p/6834711.html
Copyright © 2020-2023  润新知