Android上机实验:身高计算器的实现.pdf
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
Android上机实验:⾝⾼计算器的实现 2.对控件进⾏定义(或者导包) 3.对Button控件进⾏代码编译,实现计算的算法 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maths); package com.example.user.myapplication3; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioGroup; import android.widget.Toast; private EditText et1; private EditText et2; private CheckBox cb; private Button btn; private RadioGroup rg; int c; et1 = (EditText)findViewById(R.id.et_father); et2 = (EditText)findViewById(R.id.et_mother); cb = (CheckBox)findViewById(R.id.checkBox); c=0; btn = (Button)findViewById(R.id.button); rg = (RadioGroup)findViewById(R.id.rg); rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId){ if(checkedId == R.id.rb_boy) c = 0; else c = 1; } }); } public void onclick(View v){ String s1 = et1.getText().toString(); String s2 = et2.getText().toString(); int a1 = Integer.parseInt(s1); int a2 = Integer.parseInt(s2); if (cb.isChecked()) { double result; if (c == 0) { result = (a1 + a2)*0.54; } else { result =(a1*0.923 + a2)/2 ; } Toast.makeText(this, "结果=" + result, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "暂不提供计算", Toast.LENGTH_SHORT).show(); 六、实验操作界⾯展⽰ 七、实验总结与反思 指导⽼师在实验中进⾏了多次实际操作展⽰,是我们快速地熟悉了实验的操作流程,故在试验中遇到的困难和问题较少,希望以后每⼀次上 机操作实验都可以像这次的实验⼀样顺利,可以解决所有出现的问题,与同学们共同进步!
- 粉丝: 168
- 资源: 3万+
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助