<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="3">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="202dp"
android:layout_weight="1"
android:gravity="center"
android:text="请根据您的个人情况选择方案"
android:textSize="30sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="192dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="111dp"
android:layout_height="40dp"
android:layout_weight="1"
android:text="商业贷款" />
<EditText
android:id="@+id/Number1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="元" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="198dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView4"
android:layout_width="110dp"
android:layout_height="43dp"
android:layout_weight="1"
android:text="公积金贷款" />
<EditText
android:id="@+id/Number2"
android:layout_width="wrap_content"
android:layout_height="61dp"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="元" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="65dp"
android:text="请选择还款年数" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioGroup
android:id="@+id/ChosenYears"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="5年" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="10年" />
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="match_parent"
android:layout_height="58dp"
android:text="20年" />
</RadioGroup>
<Button
android:id="@+id/button"
android:layout_width="158dp"
android:layout_height="147dp"
android:layout_weight="1"
android:text="确定" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="确认您的利息情况" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="您共需偿还费用" />
<EditText
android:id="@+id/Number3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="元" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textView8"
android:layout_width="99dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="您每年需偿还" />
<EditText
android:id="@+id/Number4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="元" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textView10"
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="您每月需偿还" />
<EditText
android:id="@+id/Number5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="元" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.house;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private EditText Commercial_Loan;
private EditText Provident_Fund;
private EditText All;
private EditText Year;
private EditText Month;
Integer RadioGroup_Flag;//年份标识
private RadioGroup chosen_group;
private RadioButton year1;
private RadioButton year2;
private RadioButton year3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//确定按钮
View btn_submit = findViewById(R.id.button);
//单选年份
chosen_group = (RadioGroup) findViewById(R.id.ChosenYears);
year1 = (RadioButton) findViewById(R.id.radioButton1);
year2 = (RadioButton) findViewById(R.id.radioButton2);
year3 = (RadioButton) findViewById(R.id.radioButton3);
Commercial_Loan = (EditText) findViewById(R.id.Number1);//商业保险结果集
Provident_Fund = (EditText) findViewById(R.id.Number2);//公积金
All = (EditText) findViewById(R.id.Number3);//所有费用
Year = (EditText) findViewById(R.id.Number4);//每年偿还
Month = (EditText) findViewById(R.id.Number5);//每月偿还
//添加事件监听器
btn_submit.setOnClickListener(this);
//为radioGroup设置一个监听器:setOnCheckedChanged()
//chosen_group.setOnCheckedChangeListener((RadioGroup.OnCheckedChangeListener) this);
}
//监听事件,上面implements View.OnClickListener后必须重写onClick函数实现
@Override
public void onClick(View view) {
int Number_Com = Integer.parseInt(Commercial_Loan.getEditableText().toString().trim());
int Number_Fund = Integer.parseInt(Provident_Fund.getEditableText().toString().trim());
int id = chosen_group.getCheckedRadioButtonId();
int year_id = id%10;
//设置5年商贷5个点,公积金3个点 ,10年商贷4个点,公积金2个点 , 20年商贷3个点,公积金1个点。
if(year_id == 8){
Double money_all = Number_Com*1.25+Number_Fund*1.15;
All.setText(String.valueOf(money_all));
Double money_yaer = money_all/5;
Year.setText(String.valueOf(money_yaer));
Double money_month = money_all/60;
Month.setText(String.valueOf(money_month));
}else if(year_id ==9){
Double money_all = Number_Com*1.4+Number_Fund*1.2;
All.setText(String.valueOf(money_all));
Double money_yaer = money_all/10;
Year.setText(String.valueOf(money_yaer));
Double money_month = money_all/120;
Month.setText(String.valueOf(money_month));
}else if(year_id ==0){
Double money_all = Number_Com*1.6+Number_Fund*1.2;
All.setText(String.valueOf(money_all));
Double money_yaer = money_all/20;
Year.setText(String.valueOf(money_yaer));
Double money_month = money_all/240;
Month.setText(String.valueOf(money_month));
}else{
All.setText(String.valueOf(id));
Year.setText(String.valueOf(year_id));
Month.setText("Wrong!");
}
}
}