OnClickListener btnClickListener = new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub RadioButton male = (RadioButton)findViewById(R.id.male);
//sex=1 代表男性 //sex=2 代表女性
int sex = male.isChecked()?1:2;
EditText et = (EditText)findViewById(R.id.height);
//得到用户输入的身高
float height =
Float.parseFloat(et.getEditableText().toString());
float weight = getWeight(sex, height);
new AlertDialog.Builder(Main.this)
.setTitle(\体重\
.setMessage(\您的标准体重为\.setPositiveButton(\确定\new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show(); } };
//此方法用来计算标准体重
}
public float getWeight(int sex,float height){
float weight = 0.0f;
if (sex==1) {
weight = (height - 80) * 0.7f; } else {
weight = (height - 70) * 0.6f; }
return Math.round(weight); }
2. 写出按钮和按钮单击后跳转到另一个Activity(6分)
布局文件 :main.xml(写出完整控件即可)
xmlns:android=\\ android:orientation=\ android:layout_width=\ android:layout_height=\ android:background=\ > android:layout_width=\ android:layout_height=\ android:text=\ android:layout_gravity=\ android:textSize=\ android:textColor=\ android:layout_marginTop=\ android:layout_marginBottom=\ android:textStyle=\ /> android:layout_width=\ android:layout_height=\ android:background=\ android:layout_marginLeft=\ android:layout_marginRight=\ />
Activity:MainActivity.java(跳转目标OtherActivity.java)(写出关键代码即可)
import junit.framework.MainActivity; 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;
public class MainActivity extends Activity { Button wel_btn1; Button wel_btn2; Button wel_btn3;
/** Called when the activity is first created. */ @Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
wel_btn1=(Button)findViewById(R.id.wel_btn1); wel_btn2=(Button)findViewById(R.id.wel_btn2); wel_btn3=(Button)findViewById(R.id.wel_btn3);
wel_btn1.setOnClickListener(onClickListener); wel_btn2.setOnClickListener(onClickListener); wel_btn3.setOnClickListener(onClickListener); }
OnClickListener onClickListener=new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub MainActivity.this.finish(); Intent intent=new
Intent(MainActivity.this,OtherActivity.class);
}
startActivity(intent); } };
3. 写出加1 和 减1的程序主要代码(6分)
布局文件 :main.xml
- android:layout_width=\wrap_content\ android:layout_height=\wrap_content\ android:text=\每天运动:\ android:gravity=\left\18sp\ android:id=\@+id/add\ android:layout_width=\wrap_content\ android:layout_height=\wrap_content\ android:background=\@drawable/btn_add\ android:textSize=\24sp\ android:id=\@+id/result\ android:layout_width=\90dip\ android:layout_height=\wrap_content\ android:textSize=\18sp\ android:background=\#fff\ android:id=\@+id/less\ android:layout_width=\wrap_content\ android:layout_height=\wrap_content\ android:background=\@drawable/btn_less\ android:textSize=\24sp\