标准体重测量器
来源:互联网 发布:js登录注册功能 编辑:程序博客网 时间:2024/05/17 06:34
activity_main.xml
<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="@dimen/activity_vertical_margin" tools:context="com.text.weight.MainActivity" > <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="58dp" android:text="@string/word1" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/text1" android:layout_marginTop="95dp" android:text="@string/word2" /> <RadioGroup android:id="@+id/grop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/text2" android:layout_centerHorizontal="true" android:orientation="horizontal" > <RadioButton android:id="@+id/rButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rbmale" /> <RadioButton android:id="@+id/rButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rbfemale" /></RadioGroup> <TextView android:id="@+id/text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/text2" android:layout_marginTop="90dp" android:text="@string/word3"/> <EditText android:id="@+id/text4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/grop" android:layout_alignBottom="@+id/text3" android:hint="@string/input" > <requestFocus/> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="26dp" android:text="@string/b3" /> </RelativeLayout>activity_show.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/tvshow" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="130dp" android:text="" /></RelativeLayout>MainActivity.java
package com.text.weight;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;public class MainActivity extends Activity{String Sex; private Button button1; private EditText test4; private RadioGroup sex; private RadioButton choose;protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);test4 = (EditText) findViewById(R.id.text4);sex =(RadioGroup)findViewById(R.id.grop); sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup grop, int checkedID) { choose=(RadioButton) findViewById(sex.getCheckedRadioButtonId()); Sex=choose.getText().toString();}}); button1 = (Button) findViewById(R.id.button1);button1.setOnClickListener(new ClickHandler());}class ClickHandler implements OnClickListener{public void onClick(View view){Intent intent = new Intent();intent.setClass(getApplicationContext(), ShowActivity.class);Bundle bundle = new Bundle();String High =test4.getText().toString(); bundle.putString("high", High);bundle.putString("sex",Sex);intent.putExtras(bundle);startActivity(intent);}}}ShowActivity.java
package com.text.weight;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ShowActivity extends Activity { private TextView tvshow; float weight;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_show);float weight;Bundle bundle=this.getIntent().getExtras();String sex=bundle.getString("sex");String high=bundle.getString("high");float High=Float.valueOf(high).floatValue();if(sex=="男")weight=(float)((High-80)*0.7);elseweight=(float)((High-70)*0.6);tvshow=(TextView)findViewById(R.id.tvshow);tvshow.setText("你是一位"+sex+"性\n你的身高是"+high+"厘米\n你的标准体重是"+weight+"公斤\n");}}
出现的问题:
数据类型的转换:bundle传送的是string,而需要的是float类型的数据,所以一开始的时候运行出来的结果是身高为0,体重为负数。
0 0
- 标准体重测量器
- 标准体重测量器
- 标准体重
- 标准体重
- 标准体重
- 标准体重计算方法之一
- 北方男标准体重
- 计算标准体重
- 计算标准体重
- 标准体重计算器
- 标准体重计算器
- 标准体重计算器
- 标准体重计算器
- 标准体重计算器
- 标准体重计算器
- 计算标准体重
- 标准体重计算器
- 是否是标准体重
- Android组件---四大布局的属性详解
- 去哪儿校招现场面面经
- XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks
- 成功的背后!(给所有IT人)(转)
- Linux下面查看进程编号
- 标准体重测量器
- Seeing the Big Picture:Deep Embedding with Contextual Evidences
- 嵌入式Linux编译系统的设计——Bootloader, 内核,驱动,文件系统,升级镜像等自动化编译打包
- 使用Arrays类操作Java数组
- 第三方平台个推SDK的使用
- 王爽汇编第二版实验4
- A Neural Algorithm of Artistic Style--码农的文艺梦
- 朴素贝叶斯法(对于连续和离散属性的处理)
- 数据结构的主要概念