第一行代码第四日

来源:互联网 发布:千岸科技有限公司知乎 编辑:程序博客网 时间:2024/04/28 22:27

1.用Bundle和Intent传数据

传递方:

    private OnClickListener calrBMI = new OnClickListener()
    {
     public void onClick(View v)
     {

       Intent intent = new Intent();
       Bundle bundle = new Bundle();
       bundle.putString("key_height", fieldHeight.getText().toString());
       bundle.putString("key_weight", fieldWeight.getText().toString());
       intent.setClass(ActivityMain.this,Report.class);
       intent.putExtras(bundle);
       startActivity(intent);   
      
     }    
    };

接收方:

         Bundle bundle = new Bundle();
         bundle = this.getIntent().getExtras();
         double height = Double.parseDouble(bundle.getString("key_height"))/100;
         double weight = Double.parseDouble(bundle.getString("key_weight"));

2.string和final string

String a = "hello2";
final String b = "hello";
String c = "hello";
 
System.out.println(a==(b+2));
System.out.println(a==(c+2));
第一个为true,第二个为false

用final声明的变量为常量,也就是说System.out.println(a==(b+2));和System.out.println(a==("hello"+2));效果是一样的。

final关键字修饰的类不能被继承,修饰的方法不能被覆写,修饰的变量值不能修改。

0 0
原创粉丝点击