学习目标:
- 设计一个计算存款利息的UI交互页面
学习内容:
- layout文件设计
- Java程序编写 难点处理不同按钮对应计算不同金额不同年限的不同计算方式--复杂,孤立出一个函数来
- 交互
学习产出:
1在两个按钮上放监听器,本类输入
button1.setOnClickListener(this);
2文本形式获取计算
String mystr=str. getText().toString().trim();
getText()返回的是字符串trim()去除空格
float cash=Float.parseFloat(myCash);
防止不是数字或者空的强制转化定义一下layout里面Android:inputType="number"
3弹窗提示
弹完自己消退
Toast.makeText(money.this,text:"输入不能为空",Toast.LENGTH_LONG).show();
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/qian"
//加了一个酷炫背景
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="存款本金:"
android:textColor="@color/white"//酷炫背景太黑了看不见字
android:textSize="30dp"
android:layout_marginTop="30dp"/>
<EditText
android:id="@+id/n1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layo