Activity间用Intent和Bundle传递参数

来源:互联网 发布:炉石传说淘宝60包 编辑:程序博客网 时间:2024/06/05 10:31
Activity间用Intent和Bundle传递参数

http://hi.baidu.com/%C8%F0%F2%B6%CF%E9/blog/item/b969aa232d5900aa4623e8c7.html

传递方:

//点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText()

private void setListeners()
    {
    btn_sub.setOnClickListener(calrBMI);
    }
    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"));

原创粉丝点击