zoukankan      html  css  js  c++  java
  • Android全局变量使用

    1、通过一个Data.java实例类,能够实现全局数据保存,这里就不多说了,学Java的都知道。


    2、Android特有的Application,是应用的入口,执行贯穿整个app执行过程,能够在这个类中定义全局变量

    public class baseApplication extends Application {
    		
    	private float screenWidth;
    	private float screenHeight;
    	
    	
    	public float getScreenWidth() {
    		return screenWidth;
    	}
    	public void setScreenWidth(float screenWidth) {
    		this.screenWidth = screenWidth;
    	}
    	public float getScreenHeight() {
    		return screenHeight;
    	}
    	public void setScreenHeight(float screenHeight) {
    		this.screenHeight = screenHeight;
    	}
    	
    	
    }
    

    使用时候直接调用:

            
            baseApplication b=(baseApplication) getApplicationContext();
            float width=b.getScreenWidth();
            float height=b.getScreenHeight();





  • 相关阅读:
    node.js----服务器http
    node.js---对文件操作
    node.js
    历史管理
    h5
    git与github
    js中面向对象(创建对象的几种方式)
    jq基础
    POJ 2492 A Bug's Life
    POJ 1742 Coins
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3807407.html
Copyright © 2011-2022 走看看