package swufe.com.exchangerate;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText et;
TextView tv;
TextView tv2;
Button b1;
Button b2;
Button b3;
Button b4;
double bd=0.1464;
double be=0.1258;
double bw=171.9833;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et=findViewById(R.id.inp);
tv=findViewById(R.id.tv2);
b1=findViewById(R.id.btn1);
b2=findViewById(R.id.btn2);
b3=findViewById(R.id.btn3);
b4=findViewById(R.id.next);
}
public void yd(View v) {
//弹出提示信息
Toast.makeText(this, "please input number",Toast.LENGTH_SHORT).show();
//人民币转化为美元,实时的时候,就读表然后在匹配
String str1 = et.getText().toString();
//然后是转化为double类型
double a = Double.parseDouble(str1);
double b = a *bd;
String output=String.valueOf(b);
tv.setText(output+"元");
}
public void ye(View v){
String str1 = et.getText().toString();
//然后是转化为double类型
double a = Double.parseDouble(str1);
double b = a *be;
String output=String.valueOf(b);
tv.setText(output+"元");
}
public void yw(View v){
String str1 = et.getText().toString();
//然后是转化为double类型
double a = Double.parseDouble(str1);
double b = a *bw ;
String output=String.valueOf(b);
tv.setText(output+"元");
}
//传参和转到下个页面
public void nt(View v){
Intent intent=new Intent(this,MainActivity2.class);
//sec.putExtra("b1",bd);
//sec.putExtra("b2",be);
//sec.putExtra("b3",bw);
//下面这个是直接打开,不能返回数据
// startActivity(sec);
// Intent sec1=new Intent(this,MainActivity2.class);
//放在一个盒子里面,然后传过去吗?,所以要怎么接受呢,又怎么更改呢
Bundle bdl = new Bundle();
bdl.putDouble("b1",bd);
bdl.putDouble("b2",be);
bdl.putDouble("b3",bw);
intent.putExtras(bdl);
startActivityForResult(intent, 2);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if(requestCode==1 && resultCode==2){
Bundle bundle = data.getExtras();
bd= bundle.getDouble("b1",0);
be = bundle.getDouble("b2",0);
bw = bundle.getDouble("b3",0);
// }
super.onActivityResult(requestCode, resultCode, data);
tv2=findViewById(R.id.tvv);
String output3=String.valueOf(bw);
tv2.setText(output3);
}
//可以返回数据
//在函数里面怎么影响全局变量
}
没有合适的资源?快使用搜索试试~ 我知道了~
Androidstudio实现页面跳转和传递参数

身份认证 购VIP最低享 7 折!

在Androidstudio上写app,实现多页面跳转和传递参数,用bundle存取数据,可以在返回时把参数值带回来,避免丢失,顺利完成传参
资源推荐
资源详情
资源评论












收起资源包目录




共 2 条
- 1
资源评论

- 寻找以前的自己2021-11-23能不能写详细一点,就是有两个txt文件但是不知道什么意思也不知道怎么用
- Vicyn2021-02-01一般,不是完整工程
weixin_43865132
- 粉丝: 0
- 资源: 1

上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
已下载
下载帮助

内容简介:代码.rar 代码 代码 Java-2.txt java-1.txt
相关资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
