Android实现房贷计算器
作者:爱睡觉的小馨 发布时间:2022-11-23 17:58:56
标签:Android,房贷,计算器
本文实例为大家分享了Android实现房贷计算器的具体代码,供大家参考,具体内容如下
fangdai(activity)
package com.example.myapplication_one;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class fangdai extends AppCompatActivity {
? ? //声明用到的所有控件
? ? Spinner spinner1;
? ? Spinner spinner2;
? ? EditText row1edit;
? ? EditText row2edit;
? ? Button total;
? ? RadioGroup radioGroup;
? ? CheckBox checkBox1;
? ? CheckBox checkBox2;
? ? EditText row4edit;
? ? EditText row5edit;
? ? Button detail;
? ? TextView totalcal;
? ? TextView alldetail;
? ? private void initSpinner(){
? ? ? ? //初始化控件
? ? ? ? spinner1= (Spinner) findViewById(R.id.sp1);
? ? ? ? spinner2= (Spinner) findViewById(R.id.sp2);
? ? ? ? //建立数据源
? ? ? ? String[] years=getResources().getStringArray(R.array.years);
? ? ? ? String[] baserates=getResources().getStringArray(R.array.baserate);
? ? ? ? //声明一个下拉列表的数组适配器并绑定数据源
? ? ? ? ArrayAdapter<String> yearAdapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,years);
? ? ? ? ArrayAdapter<String> baserateAdapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,baserates);
? ? ? ? //绑定Adapter到控件
? ? ? ? spinner1.setAdapter(yearAdapter);
? ? ? ? spinner2.setAdapter(baserateAdapter);
? ? ? ? //设置默认选择第一项
? ? ? ? spinner1.setSelection(0);
? ? ? ? spinner2.setSelection(0);
? ? ? ? //设置标题
? ? ? ? spinner1.setPrompt("请选择贷款年限");
? ? ? ? spinner2.setPrompt("请选择基准利率");
? ? }
? ? //声明下列函数中要用到的变量
? ? double intotal,backtotal,extra,pertime;//贷款总额,还款总额,利息,每月还款总额
? ? int month;//月份
? ? String buytotal;//购房总额
? ? String percent;//贷款百分比
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.fangdai);
? ? ? ? //初始化控件
? ? ? ? initSpinner();
? ? ? ? row1edit= (EditText) findViewById(R.id.row1edit);
? ? ? ? row2edit= (EditText) findViewById(R.id.row2edit);
? ? ? ? total= (Button) findViewById(R.id.totalcal);
? ? ? ? radioGroup= (RadioGroup) findViewById(R.id.radiogroup);
? ? ? ? checkBox1= (CheckBox) findViewById(R.id.check1);
? ? ? ? checkBox2= (CheckBox) findViewById(R.id.check2);
? ? ? ? totalcal= (TextView) findViewById(R.id.showtotal);
? ? ? ? detail= (Button) findViewById(R.id.detail);
? ? ? ? alldetail= (TextView) findViewById(R.id.alldetail);
? ? ? ? row4edit= (EditText) findViewById(R.id.row4label);
? ? ? ? row5edit= (EditText) findViewById(R.id.row5label);
? ? ? ? //给第一个计算按钮添加点击监听
? ? ? ? total.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? buytotal=row1edit.getText().toString();
? ? ? ? ? ? ? ? percent=row2edit.getText().toString();
? ? ? ? ? ? ? ? if(TextUtils.isEmpty(buytotal)||TextUtils.isEmpty(percent))//判断前两个输入框是否非空
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"购房总价和按揭部分信息填写完整",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? }else if(fangdaitext.isNum(buytotal)==false||fangdaitext.isNum(percent)==false){//判断输入的是否是数字
? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"包含不合法的输入信息",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? } else if(Double.parseDouble(percent)>100){//判断百分比部分输入是否大于100%
? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"按揭部分不能超过100%",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? } else if(fangdaitext.isNum(buytotal)&&fangdaitext.isNum(percent))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? intotal=(Double.parseDouble(buytotal)*Double.parseDouble(percent)*0.01);
? ? ? ? ? ? ? ? ? ? totalcal.setText("您的贷款总额为"+String.format("%.2f",intotal)+"万元");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? detail.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? //first,second为商贷和公积金贷所填数值
? ? ? ? ? ? ? ? String first=row4edit.getText().toString();
? ? ? ? ? ? ? ? String second=row5edit.getText().toString();
? ? ? ? ? ? ? ? //firstrate和secondrate为商贷和公积金的年利率
? ? ? ? ? ? ? ? double firstrate=Double.parseDouble(spinner2.getSelectedItem().toString().substring(20,24))*0.01;
? ? ? ? ? ? ? ? double secondrate=Double.parseDouble(spinner2.getSelectedItem().toString().substring(31,35))*0.01;
? ? ? ? ? ? ? ? //获取下拉列表的年份求得月份
? ? ? ? ? ? ? ? String year=spinner1.getSelectedItem().toString();
? ? ? ? ? ? ? ? month=Integer.parseInt(year.substring(0,year.length()-1))*12;
? ? ? ? ? ? ? ? //两种贷款的月利率
? ? ? ? ? ? ? ? double firstmonthrate=firstrate/12;
? ? ? ? ? ? ? ? double secondmonthrate=secondrate/12;
? ? ? ? ? ? ? ? if(totalcal.getText().toString().equals("其中贷款部分为:***万")){//判断是否计算过贷款总额
? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"请先计算贷款总额",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? }else if(row1edit.getText().toString().equals(buytotal)==false||row2edit.getText().toString().equals(percent)==false){//监听贷款总额和按揭部分数值是否发生变化
? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"检查到您的购房总价或按揭部分数据更改,请重新计算贷款总额",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? } else if(checkBox1.isChecked()==false&&checkBox2.isChecked()==false)//监听勾选的多选框
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"请勾选贷款种类",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? }else if(checkBox1.isChecked()&&checkBox2.isChecked()==false){
? ? ? ? ? ? ? ? ? ? //等额本息贷款算法
? ? ? ? ? ? ? ? ? ? if(radioGroup.getCheckedRadioButtonId()==R.id.btn1){
? ? ? ? ? ? ? ? ? ? ? ? pertime=intotal*firstmonthrate*Math.pow((1+firstmonthrate),month)/(Math.pow(1+firstmonthrate,month)-1);
? ? ? ? ? ? ? ? ? ? ? ? backtotal=pertime*month;
? ? ? ? ? ? ? ? ? ? ? ? extra=backtotal-intotal;
? ? ? ? ? ? ? ? ? ? ? ? alldetail.setText("您的贷款总额为"+String.format("%.2f",intotal)+"万元\n还款总额为"+String.format("%.2f",backtotal)+"万元\n其中利息总额为"+String.format("%.2f",extra)+"万元\n还款总时间为"+month+"月\n每月还款金额为"+String.format("%.2f",pertime*10000)+"元");
? ? ? ? ? ? ? ? ? ? }else{//等额本金贷款算法
? ? ? ? ? ? ? ? ? ? ? ? double[] array=new double[month];
? ? ? ? ? ? ? ? ? ? ? ? double sum=0;
? ? ? ? ? ? ? ? ? ? ? ? for(int i=0;i<month;i++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? array[i]=intotal/month+(intotal-sum)*firstmonthrate;
? ? ? ? ? ? ? ? ? ? ? ? ? ? sum+=array[i];
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? String text="";
? ? ? ? ? ? ? ? ? ? ? ? for(int i=0;i<month;i++){
? ? ? ? ? ? ? ? ? ? ? ? ? ? text+="\n第"+(i+1)+"个月应还金额为:"+String.format("%.2f",array[i]*10000);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? backtotal=sum;
? ? ? ? ? ? ? ? ? ? ? ? extra=backtotal-intotal;
? ? ? ? ? ? ? ? ? ? ? ? alldetail.setText("您的贷款总额为"+String.format("%.2f",intotal)+"万元\n还款总额为"+String.format("%.2f",backtotal)+"万元\n其中利息总额为"+String.format("%.2f",extra)+"万元\n还款总时间为"+month+"月\n每月还款金额如下:"+text);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }else if(checkBox1.isChecked()==false&&checkBox2.isChecked()){
? ? ? ? ? ? ? ? ? ? if(radioGroup.getCheckedRadioButtonId()==R.id.btn1){
? ? ? ? ? ? ? ? ? ? ? ? pertime=intotal*secondmonthrate*Math.pow((1+secondmonthrate),month)/(Math.pow(1+secondmonthrate,month)-1);
? ? ? ? ? ? ? ? ? ? ? ? backtotal=pertime*month;
? ? ? ? ? ? ? ? ? ? ? ? extra = backtotal - intotal;
? ? ? ? ? ? ? ? ? ? ? ? alldetail.setText("您的贷款总额为" + String.format("%.2f",intotal) + "万元\n还款总额为"+String.format("%.2f",backtotal)+"万元\n其中利息总额为"+String.format("%.2f",extra)+"万元\n还款总时间为"+month+"月\n每月还款金额为"+String.format("%.2f",pertime*10000)+"元");
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? double[] array=new double[month];
? ? ? ? ? ? ? ? ? ? ? ? double sum=0;
? ? ? ? ? ? ? ? ? ? ? ? for(int i=0;i<month;i++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? array[i]=intotal/month+(intotal-sum)*secondmonthrate;
? ? ? ? ? ? ? ? ? ? ? ? ? ? sum+=array[i];
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? String text="";
? ? ? ? ? ? ? ? ? ? ? ? for(int i=0;i<month;i++){
? ? ? ? ? ? ? ? ? ? ? ? ? ? text+="\n第"+(i+1)+"个月应还金额为:"+String.format("%.2f",array[i]*10000)+"元";
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? backtotal=sum;
? ? ? ? ? ? ? ? ? ? ? ? extra=backtotal-intotal;
? ? ? ? ? ? ? ? ? ? ? ? alldetail.setText("您的贷款总额为"+String.format("%.2f",intotal)+"万元\n还款总额为"+String.format("%.2f",backtotal)+"万元\n其中利息总额为"+String.format("%.2f",extra)+"万元\n还款总时间为"+month+"月\n每月还款金额如下:"+text);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }else if(checkBox1.isChecked()&&checkBox2.isChecked()){
? ? ? ? ? ? ? ? ? ? if(radioGroup.getCheckedRadioButtonId()==R.id.btn1){
? ? ? ? ? ? ? ? ? ? ? ? if(TextUtils.isEmpty(first)||TextUtils.isEmpty(second)){
? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"请将空信息填写完整",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? ? ? ? ? }else if(fangdaitext.isNum(first)==false||fangdaitext.isNum(second)==false){
? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"包含不合法的输入信息",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? ? ? ? ? }else if(Double.parseDouble(first)+Double.parseDouble(second)!=Double.parseDouble(String.format("%.2f",intotal))){
? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"填写的两项贷款总额不等于初始贷款额度,请重新填写",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? double p1=Double.parseDouble(first);
? ? ? ? ? ? ? ? ? ? ? ? ? ? double p2=Double.parseDouble(second);
? ? ? ? ? ? ? ? ? ? ? ? ? ? double pertime1=p1*firstmonthrate*Math.pow((1+firstmonthrate),month)/(Math.pow(1+firstmonthrate,month)-1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? double pertime2=p2*secondmonthrate*Math.pow((1+secondmonthrate),month)/(Math.pow(1+secondmonthrate,month)-1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? pertime=pertime1+pertime2;
? ? ? ? ? ? ? ? ? ? ? ? ? ? backtotal=pertime*month;
? ? ? ? ? ? ? ? ? ? ? ? ? ? extra=backtotal-intotal;
? ? ? ? ? ? ? ? ? ? ? ? ? ? alldetail.setText("您的贷款总额为" + String.format("%.2f",intotal) + "万元\n还款总额为"+String.format("%.2f",backtotal)+"万元\n其中利息总额为"+String.format("%.2f",extra)+"万元\n还款总时间为"+month+"月\n每月还款金额为"+String.format("%.2f",pertime*10000)+"元");
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? if(first.equals("请输入商业贷款总额(单位万)")||second.equals("请输入公积金贷款总额(单位万)")){
? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"请将空信息填写完整",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? ? ? ? ? }else if(fangdaitext.isNum(first)==false||fangdaitext.isNum(second)==false){
? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"包含不合法的输入信息",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? ? ? ? ? }else if(Double.parseDouble(first)+Double.parseDouble(second)!=Double.parseDouble(String.format("%.2f",intotal))){
? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,"填写的两项贷款总额不等于初始贷款额度,请重新填写",Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? double p1=Double.parseDouble(first);
? ? ? ? ? ? ? ? ? ? ? ? ? ? double p2=Double.parseDouble(second);
? ? ? ? ? ? ? ? ? ? ? ? ? ? double[] array1=new double[month];
? ? ? ? ? ? ? ? ? ? ? ? ? ? double[] array2=new double[month];
? ? ? ? ? ? ? ? ? ? ? ? ? ? double sum1=0,sum2=0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? for(int i=0;i<month;i++)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? array1[i]=p1/month+(p1-sum1)*firstmonthrate;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? array2[i]=p2/month+(p2-sum2)*secondmonthrate;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(fangdai.this,array1[i]+" "+array2[i],Toast.LENGTH_LONG);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sum1+=array1[i];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sum2+=array2[i];
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? String text="";
? ? ? ? ? ? ? ? ? ? ? ? ? ? for(int i=0;i<month;i++){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? text+="\n第"+(i+1)+"个月应还金额为:"+String.format("%.2f",(array1[i]+array2[i])*10000)+"元";
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? backtotal=sum1+sum2;
? ? ? ? ? ? ? ? ? ? ? ? ? ? extra=backtotal-intotal;
? ? ? ? ? ? ? ? ? ? ? ? ? ? alldetail.setText("您的贷款总额为"+String.format("%.2f",intotal)+"万元\n还款总额为"+String.format("%.2f",backtotal)+"万元\n其中利息总额为"+String.format("%.2f",extra)+"万元\n还款总时间为"+month+"月\n每月还款金额如下:"+text);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? row1edit.addTextChangedListener(new TextWatcher() {
? ? ? ? ? ? int oldlength=0;
? ? ? ? ? ? @Override
? ? ? ? ? ? public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {//强制用户不能输入非数字和小数点之外的字符
? ? ? ? ? ? ? ? int length = charSequence.length();
? ? ? ? ? ? ? ? if (length > oldlength) {
? ? ? ? ? ? ? ? ? ? char newchar = charSequence.charAt(i);
? ? ? ? ? ? ? ? ? ? if ((newchar < '0' && newchar > '9') && newchar != '.') {
? ? ? ? ? ? ? ? ? ? ? ? if (i != length - 1)
? ? ? ? ? ? ? ? ? ? ? ? ? ? row1edit.setText(charSequence.subSequence(0, i).toString() + charSequence.subSequence(i + 1, length).toString());
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? row1edit.setText(charSequence.subSequence(0, length - 1));
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? oldlength=length;
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void afterTextChanged(Editable editable) {
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? row2edit.addTextChangedListener(new TextWatcher() {
? ? ? ? ? ? int oldlength=0;
? ? ? ? ? ? @Override
? ? ? ? ? ? public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
? ? ? ? ? ? ? ? int length=charSequence.length();
? ? ? ? ? ? ? ? if(length>oldlength) {
? ? ? ? ? ? ? ? ? ? char newchar = charSequence.charAt(i);
? ? ? ? ? ? ? ? ? ? if ((newchar < '0' && newchar > '9') && newchar != '.') {
? ? ? ? ? ? ? ? ? ? ? ? if (i != length - 1)
? ? ? ? ? ? ? ? ? ? ? ? ? ? row2edit.setText(charSequence.subSequence(0, i).toString() + charSequence.subSequence(i + 1, length).toString());
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? row2edit.setText(charSequence.subSequence(0, length - 1));
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? oldlength=length;
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void afterTextChanged(Editable editable) {
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? row4edit.addTextChangedListener(new TextWatcher() {
? ? ? ? ? ? int oldlength=0;
? ? ? ? ? ? @Override
? ? ? ? ? ? public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
? ? ? ? ? ? ? ? int length=charSequence.length();
? ? ? ? ? ? ? ? if(length>oldlength) {
? ? ? ? ? ? ? ? ? ? char newchar = charSequence.charAt(i);
? ? ? ? ? ? ? ? ? ? if ((newchar < '0' && newchar > '9') && newchar != '.') {
? ? ? ? ? ? ? ? ? ? ? ? if (i != length - 1)
? ? ? ? ? ? ? ? ? ? ? ? ? ? row4edit.setText(charSequence.subSequence(0, i).toString() + charSequence.subSequence(i + 1, length).toString());
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? row4edit.setText(charSequence.subSequence(0, length - 1));
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? oldlength=length;
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void afterTextChanged(Editable editable) {
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? row5edit.addTextChangedListener(new TextWatcher() {
? ? ? ? ? ? int oldlength=0;
? ? ? ? ? ? @Override
? ? ? ? ? ? public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
? ? ? ? ? ? ? ? int length=charSequence.length();
? ? ? ? ? ? ? ? if(length>oldlength) {
? ? ? ? ? ? ? ? ? ? char newchar = charSequence.charAt(i);
? ? ? ? ? ? ? ? ? ? if ((newchar < '0' && newchar > '9') && newchar != '.') {
? ? ? ? ? ? ? ? ? ? ? ? if (i != length - 1)
? ? ? ? ? ? ? ? ? ? ? ? ? ? row5edit.setText(charSequence.subSequence(0, i).toString() + charSequence.subSequence(i + 1, length).toString());
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? row5edit.setText(charSequence.subSequence(0, length - 1));
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? oldlength=length;
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void afterTextChanged(Editable editable) {
? ? ? ? ? ? }
? ? ? ? });
? ? }
}
fangdaitext(activity)
package com.example.myapplication_one;
public class fangdaitext {
? ? public static boolean isNum(String string){
? ? ? ? int flag=0;
? ? ? ? if(string.charAt(0)=='0'&&string.charAt(1)!='.')
? ? ? ? ? ? return false;
? ? ? ? if(string.charAt(0)=='.')
? ? ? ? ? ? return false;
? ? ? ? for(int i=0;i<string.length();i++)
? ? ? ? {
? ? ? ? ? ? if((string.charAt(i)<'0'||string.charAt(i)>'9')&&string.charAt(i)!='.')
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? else if(string.charAt(i)=='.')
? ? ? ? ? ? {
? ? ? ? ? ? ? ? flag++;
? ? ? ? ? ? ? ? if(flag>1)
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return true;
? ? }
}
fangdai.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:paddingBottom="@dimen/activity_vertical_margin"
? ? android:paddingLeft="@dimen/activity_horizontal_margin"
? ? android:paddingRight="@dimen/activity_horizontal_margin"
? ? android:paddingTop="16dp"
? ? android:focusableInTouchMode="true"
? ? android:focusable="true"
? ? tools:context="com.example.myapplication_one.fangdai">
? ? <ScrollView
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content">
? ? ? ? <RelativeLayout
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="wrap_content">
? ? ? ? ? ? <RelativeLayout
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:id="@+id/relativeLayout1">
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:id="@+id/row1label"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="购房总价:"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:textSize="18sp"
? ? ? ? ? ? ? ? ? ? />
? ? ? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? ? ? android:id="@+id/row1edit"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:hint="请输入购房总价(单位万)"
? ? ? ? ? ? ? ? ? ? android:singleLine="true"
? ? ? ? ? ? ? ? ? ? android:textSize="16dp"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/edittext_style"
? ? ? ? ? ? ? ? ? ? android:padding="5dp"
? ? ? ? ? ? ? ? ? ? android:gravity="right"
? ? ? ? ? ? ? ? ? ? android:layout_toRightOf="@+id/row1label"
? ? ? ? ? ? ? ? ? ? android:layout_toLeftOf="@+id/row1endlabel"
? ? ? ? ? ? ? ? ? ? android:inputType="numberDecimal"/>
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="万"
? ? ? ? ? ? ? ? ? ? android:textSize="18sp"
? ? ? ? ? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:layout_alignParentEnd="true"
? ? ? ? ? ? ? ? ? ? android:id="@+id/row1endlabel"
? ? ? ? ? ? ? ? ? ? android:layout_alignParentRight="true" />
? ? ? ? ? ? </RelativeLayout>
? ? ? ? ? ? <RelativeLayout
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:id="@+id/relativeLayout2"
? ? ? ? ? ? ? ? android:layout_below="@+id/relativeLayout1"
? ? ? ? ? ? ? ? android:layout_marginTop="20dp">
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:id="@+id/row2label"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="按揭部分:"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:textSize="18sp"
? ? ? ? ? ? ? ? ? ? />
? ? ? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? ? ? android:id="@+id/row2edit"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:hint="请输入按揭百分比"
? ? ? ? ? ? ? ? ? ? android:singleLine="true"
? ? ? ? ? ? ? ? ? ? android:textSize="16dp"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/edittext_style"
? ? ? ? ? ? ? ? ? ? android:padding="5dp"
? ? ? ? ? ? ? ? ? ? android:gravity="right"
? ? ? ? ? ? ? ? ? ? android:layout_toRightOf="@+id/row2label"
? ? ? ? ? ? ? ? ? ? android:layout_toLeftOf="@+id/row2endlabel"
? ? ? ? ? ? ? ? ? ? android:inputType="numberDecimal"/>
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text=" %"
? ? ? ? ? ? ? ? ? ? android:textSize="18sp"
? ? ? ? ? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:layout_alignParentEnd="true"
? ? ? ? ? ? ? ? ? ? android:id="@+id/row2endlabel"
? ? ? ? ? ? ? ? ? ? android:layout_alignParentRight="true" />
? ? ? ? ? ? </RelativeLayout>
? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/totalcal"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_below="@+id/relativeLayout2"
? ? ? ? ? ? ? ? android:layout_marginTop="15dp"
? ? ? ? ? ? ? ? android:background="@drawable/btn_style"
? ? ? ? ? ? ? ? android:text="计算贷款总额" />
? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="其中贷款部分为:***万"
? ? ? ? ? ? ? ? android:layout_below="@+id/totalcal"
? ? ? ? ? ? ? ? android:layout_marginTop="10dp"
? ? ? ? ? ? ? ? android:textSize="16sp"
? ? ? ? ? ? ? ? android:id="@+id/showtotal"/>
? ? ? ? ? ? <RelativeLayout
? ? ? ? ? ? ? ? android:id="@+id/relativeLayout3"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_below="@+id/showtotal"
? ? ? ? ? ? ? ? android:layout_marginTop="10dp">
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:id="@+id/row3label"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="还款方式:"
? ? ? ? ? ? ? ? ? ? android:textSize="16sp"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"/>
? ? ? ? ? ? ? ? <RadioGroup
? ? ? ? ? ? ? ? ? ? android:id="@+id/radiogroup"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_toRightOf="@+id/row3label"
? ? ? ? ? ? ? ? ? ? android:orientation="horizontal">
? ? ? ? ? ? ? ? ? ? <RadioButton
? ? ? ? ? ? ? ? ? ? ? ? android:id="@+id/btn1"
? ? ? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? ? ? android:text="等额本息"
? ? ? ? ? ? ? ? ? ? ? ? android:checked="true"/>
? ? ? ? ? ? ? ? ? ? <RadioButton
? ? ? ? ? ? ? ? ? ? ? ? android:id="@+id/btn2"
? ? ? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? ? ? android:text="等额本金"
? ? ? ? ? ? ? ? ? ? ? ? android:layout_marginLeft="10dp"/>
? ? ? ? ? ? ? ? </RadioGroup>
? ? ? ? ? ? </RelativeLayout>
? ? ? ? ? ? <RelativeLayout
? ? ? ? ? ? ? ? android:id="@+id/relativeLayout4"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_below="@+id/relativeLayout3">
? ? ? ? ? ? ? ? <CheckBox
? ? ? ? ? ? ? ? ? ? android:id="@+id/check1"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="商贷: ? ?"/>
? ? ? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? ? ? android:id="@+id/row4label"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:hint="请输入商业贷款总额(单位万)"
? ? ? ? ? ? ? ? ? ? android:singleLine="true"
? ? ? ? ? ? ? ? ? ? android:textSize="16dp"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/edittext_style"
? ? ? ? ? ? ? ? ? ? android:padding="5dp"
? ? ? ? ? ? ? ? ? ? android:gravity="right"
? ? ? ? ? ? ? ? ? ? android:layout_toRightOf="@+id/check1"
? ? ? ? ? ? ? ? ? ? android:layout_toLeftOf="@+id/row4endlabel"
? ? ? ? ? ? ? ? ? ? android:inputType="numberDecimal"/>
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="万"
? ? ? ? ? ? ? ? ? ? android:textSize="18sp"
? ? ? ? ? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:layout_alignParentEnd="true"
? ? ? ? ? ? ? ? ? ? android:id="@+id/row4endlabel"/>
? ? ? ? ? ? </RelativeLayout>
? ? ? ? ? ? <RelativeLayout
? ? ? ? ? ? ? ? android:id="@+id/relativeLayout5"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_below="@+id/relativeLayout4"
? ? ? ? ? ? ? ? android:layout_marginTop="5dp">
? ? ? ? ? ? ? ? <CheckBox
? ? ? ? ? ? ? ? ? ? android:id="@+id/check2"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="公积金:"/>
? ? ? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? ? ? android:id="@+id/row5label"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:hint="请输入公积金贷款总额(单位万)"
? ? ? ? ? ? ? ? ? ? android:singleLine="true"
? ? ? ? ? ? ? ? ? ? android:textSize="16dp"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/edittext_style"
? ? ? ? ? ? ? ? ? ? android:padding="5dp"
? ? ? ? ? ? ? ? ? ? android:gravity="right"
? ? ? ? ? ? ? ? ? ? android:layout_toRightOf="@+id/check2"
? ? ? ? ? ? ? ? ? ? android:layout_toLeftOf="@+id/row5endlabel"
? ? ? ? ? ? ? ? ? ? android:inputType="numberDecimal"/>
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="万"
? ? ? ? ? ? ? ? ? ? android:textSize="18sp"
? ? ? ? ? ? ? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:layout_alignParentEnd="true"
? ? ? ? ? ? ? ? ? ? android:id="@+id/row5endlabel" />
? ? ? ? ? ? </RelativeLayout>
? ? ? ? ? ? <RelativeLayout
? ? ? ? ? ? ? ? android:id="@+id/relativeLayout6"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_below="@id/relativeLayout5"
? ? ? ? ? ? ? ? android:layout_marginTop="10dp">
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:id="@+id/row6label"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="贷款年限:"
? ? ? ? ? ? ? ? ? ? android:textSize="16sp"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"/>
? ? ? ? ? ? ? ? <Spinner
? ? ? ? ? ? ? ? ? ? android:id="@+id/sp1"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:spinnerMode="dialog"
? ? ? ? ? ? ? ? ? ? android:layout_toRightOf="@+id/row6label">
? ? ? ? ? ? ? ? </Spinner>
? ? ? ? ? ? </RelativeLayout>
? ? ? ? ? ? <RelativeLayout
? ? ? ? ? ? ? ? android:id="@+id/relativeLayout7"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_below="@+id/relativeLayout6"
? ? ? ? ? ? ? ? android:layout_marginTop="10dp">
? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:id="@+id/row7label"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:text="基准利率:"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:textSize="16sp"/>
? ? ? ? ? ? ? ? <Spinner
? ? ? ? ? ? ? ? ? ? android:id="@+id/sp2"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:spinnerMode="dialog"
? ? ? ? ? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? ? ? ? ? android:layout_toRightOf="@+id/row7label">
? ? ? ? ? ? ? ? </Spinner>
? ? ? ? ? ? </RelativeLayout>
? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/detail"
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_below="@+id/relativeLayout7"
? ? ? ? ? ? ? ? android:layout_marginTop="15dp"
? ? ? ? ? ? ? ? android:background="@drawable/btn_style"
? ? ? ? ? ? ? ? android:text="计算还款明细"/>
? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="还款总额为:***万\n其中利息总额为:***万\n月供(每月还款额)为:***"
? ? ? ? ? ? ? ? android:layout_below="@+id/detail"
? ? ? ? ? ? ? ? android:layout_marginTop="10dp"
? ? ? ? ? ? ? ? android:textSize="16sp"
? ? ? ? ? ? ? ? android:id="@+id/alldetail"/>
? ? ? ? </RelativeLayout>
? ? </ScrollView>
</RelativeLayout>
edittext_style.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
? ? <item android:state_focused="true">
? ? ? ? <shape>
? ? ? ? ? ? <corners android:radius="5dp"/>
? ? ? ? ? ? <stroke android:width="1dp"
? ? ? ? ? ? ? ? android:color="#00DDFF"/>
? ? ? ? </shape>
? ? </item>
? ? <item android:state_focused="false">
? ? ? ? <shape>
? ? ? ? ? ? <corners android:radius="5dp"/>
? ? ? ? ? ? <stroke android:width="1dp"
? ? ? ? ? ? ? ? android:color="#000000"/>
? ? ? ? </shape>
? ? </item>
</selector>
btn_style.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
? ? <item android:state_pressed="true">
? ? ? ? <shape>
? ? ? ? ? ? <solid android:color="#808080"/>
? ? ? ? ? ? <corners android:radius="2dp"/>
? ? ? ? ? ? <stroke android:width="1dp"
? ? ? ? ? ? ? ? android:color="@color/teal_200"/>
? ? ? ? </shape>
? ? </item>
? ? <item android:state_pressed="false">
? ? ? ? <shape>
? ? ? ? ? ? <solid android:color="#33E3F3"/>
? ? ? ? ? ? <corners android:radius="2dp"/>
? ? ? ? ? ? <stroke android:width="1dp"
? ? ? ? ? ? ? ? android:color="#07AC78"/>
? ? ? ? </shape>
? ? </item>
</selector>
dimens.xml
<resources>
? ? <!-- Default screen margins, per the Android Design guidelines. -->
? ? <dimen name="activity_horizontal_margin">16dp</dimen>
? ? <dimen name="activity_vertical_margin">16dp</dimen>
</resources>
来源:https://blog.csdn.net/qq_45696288/article/details/121049619
0
投稿
猜你喜欢
- 本文实例讲述了Android编程实现左右滑动切换背景的方法。分享给大家供大家参考,具体如下:最近想做一个左右滑动切换背景图片的应用,特地将自
- 0 问题描述一个应用在运行一段时间后,随着访问量不断增加,突然处理能力下降。但是从流量,jstack,gc上看基本正常。感觉好像突然从 “健
- 本文实例讲述了C#使用默认浏览器打开网页的方法。分享给大家供大家参考。具体实现方法如下:public static bool OpenBro
- 问题描述最近IDEA抽风了,不管是新建SpringBoot工程,还是导入项目。IDEA代码里面都会飘红~Build项目时,会提示错误:错误:
- 一、讲个事故接口安全老生常谈了过年之前做了过一款飞机大战的H5小游戏,里面无限模式-需要保存用户的积分,因为使用的Body传参,参数是可见的
- 来源:https://www.cnblogs.com/fanweisheng/p/11440
- 场景:简单工厂时候,我设计了一个场景,有三种剑去打怪,这时候,需求变化了,我三种剑变成了,匕首、剑以及木棒,想要用工厂方法来实现,怎么弄?1
- 对 Debug 的好奇初学 Java 时,我对 IDEA 的 Debug 非常好奇,不止是它能查看断点的上下文环境,更神奇的是我可以在断点处
- 按照官方文档进行的配置:快速开始|mybatis-plus引入依赖:<!-- 引入mybatisPlus --> &
- 题目:若希望循环队列中的元素都能得到利用,则需设置一个标志域tag,并以tag的值为0或1来区分队头指针front和队尾指针rear相同时的
- 本文实例为大家分享了java实现递归菜单树的具体代码,供大家参考,具体内容如下1.表结构SET FOREIGN_KEY_CHECKS=0;-
- C#中using指令的用法1.using指令using + 命名空间名字,这样可以在程序中直接用命令空间中的类型,而不必指定类型的详细命名空
- 对于数据的访问来说,肯定是在有缓存的情况下运行快一些。对于Hibernate这种与数据库结合紧密的框架来说,在调用数据的时候肯定会有缓存的出
- 当数据量比较大的时候,我们就需要考虑读写分离了,也就是动态切换数据库连接,对指定的数据库进行操作。在spring中实现动态的切换无非就是利用
- 目标本文提供一种自定义注解,来实现业务审批操作的DEMO,不包含审批流程的配置功能。具体方案是自定义一个Aspect注解,拦截sevice方
- 静态方法可以不用创建对象就调用,非静态方法必须有了对象的实例才能调用。因此想在静态方法中直接引用非静态方法是不可能的,因为不知道调用哪个对象
- java 中 System.out.println()和System.out.write()的区别.这两个函数一个是System
- 死锁在多线程的情况下,会出现数据不同步情况, 而为了避免这种情况,之前也说了:界区实现方法有两种,一种是用synchronized,一种是用
- 一般要做正圆形图片,只能是正方形的基础上才能实现,否则就变成椭圆了,下面说说如何使长方形的图片生成正圆形图片废话不多说,没图没真相,先上图吧
- 1 需求描述我们现在要干一个什么事情呢,我们要在浏览器输入一个请求地址,然后我们的后端就给我返回一个User对象即可,并且我希望以Json的