Android实现体重测量仪的源码

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
public class BundleObject extends Activity {
private Button mButton;
private EditText mEditText;
private RadioGroup mRadioGroup;
private double height;
private String Sex;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton=(Button)findViewById(R.id.confirm);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mEditText=(EditText)findViewById(R.id.heigt);
if(mEditText.getText().toString().length()==0)
{
/* AlertDialog builder = new AlertDialog.Builder(BundleObject.this).create();
builder.setTitle("提示");
builder.setMessage("請輸入您的身高!!");
builder.show();*/
new AlertDialog.Builder(BundleObject.this)
.setMessage("请輸入您的身高")
.setTitle("提示")
.setNeutralButton("确定",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
mEditText.setHighlightColor(Color.RED);
}
}).create()
.show();
return;
}
mRadioGroup=(RadioGroup)findViewById(R.id.sex);
height=Double.parseDouble(mEditText.getText().toString());
if(mRadioGroup.getCheckedRadioButtonId()==R.id.M)
{
Sex="M";
}
else
{
Sex="F";
}
Intent intent=new Intent();
intent.setClass(BundleObject.this, Next.class);
Bundle bun=new Bundle();
bun.putDouble("Height", height);
bun.putString("Sex", Sex);
intent.putExtras(bun);
startActivity(intent);
BundleObject.this.finish();
}
});
}
}

Android相关内容:

猜你喜欢

转载自star65225692.iteye.com/blog/1808202