zoukankan      html  css  js  c++  java
  • 4月2日学习日志

    今天学习了handle消息回传机制。

    主要代码为:

    public class MainActivity extends Activity {  
      
        //定义切换的图片的数组id  
        int imgids[] = new int[]{  
            R.drawable.s_1, R.drawable.s_2,R.drawable.s_3,  
            R.drawable.s_4,R.drawable.s_5,R.drawable.s_6,  
            R.drawable.s_7,R.drawable.s_8  
        };  
        int imgstart = 0;  
          
        final Handler myHandler = new Handler()  
        {  
          @Override  
          //重写handleMessage方法,根据msg中what的值判断是否执行后续操作  
          public void handleMessage(Message msg) {  
            if(msg.what == 0x123)  
               {  
                imgchange.setImageResource(imgids[imgstart++ % 8]);  
               }  
            }  
        };  
        
          
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.activity_main);  
            final ImageView imgchange = (ImageView) findViewById(R.id.imgchange);  
             
            //使用定时器,每隔200毫秒让handler发送一个空信息  
            new Timer().schedule(new TimerTask() {            
                @Override  
                public void run() {  
                    myHandler.sendEmptyMessage(0x123);  
                      
                }  
            }, 0,200);  
        }  
      
    } 
  • 相关阅读:
    Python将字符串转换成字典
    MySQL索引、视图
    MySQL高级查询
    MySQL函数应用
    MySQL约束
    MySQL基础查询
    MySQL数据库基本语法
    MySQL数据库存储引擎
    MySQL数据库简介与命令行操作
    MySQL 安装和配置环境变量
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14883212.html
Copyright © 2011-2022 走看看