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();
    }

    }
    }
    }

  • 相关阅读:
    BeautifulSoup模块
    爬取校花网视频
    爬虫基本原理
    python学习笔记-50 使用SQLAlchemy
    python学习笔记-49 使用MySQL
    PTA天梯 L3-007 天梯地图
    VS2013 创建ASP.NET MVC 4.0 未指定的错误(异常来自HRESULT: 0x80004005(e_fail))
    动态规划--新手
    文件上传绕过
    C# → 数据库
  • 原文地址:https://www.cnblogs.com/xiaoshumiao/p/6834711.html
Copyright © 2011-2022 走看看