package com.example.payne.bmi_calculator;import android.content.Intent;import android.content.res.ColorStateList;import android.graphics.Color;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.ProgressBar;import android.widget.TextView;public class Main2Activity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); setTitle("BMI計算結果"); final ProgressBar progressBar=(ProgressBar)findViewById(R.id.progressBar); final TextView gender=(TextView)findViewById(R.id.gender); final TextView bmi=(TextView)findViewById(R.id.bmi); final TextView result=(TextView)findViewById(R.id.result); final Button again=(Button)findViewById(R.id.again); Bundle bundle2=getIntent().getExtras(); double BMI=bundle2.getDouble("bmi"); progressBar.setProgress((int)((BMI-14)/18*100)); bmi.setText(String.format("%.1f",BMI)); switch (bundle2.getInt("gender")){ case 0: gender.setText("男性"); break; case 1: gender.setText("女性"); break; } if(BMI<18.5){ progressBar.setProgressTintList(ColorStateList.valueOf(Color.BLUE)); result.setText("過輕"); } else if(BMI<23){ progressBar.setProgressTintList(ColorStateList.valueOf(Color.GREEN)); result.setText("正常"); } else if(BMI<27.5){ progressBar.setProgressTintList(ColorStateList.valueOf(Color.YELLOW)); result.setText("過重"); } else { progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED)); result.setText("肥胖"); } again.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { finish(); } }); }}
评论