关闭

简单的Android页面跳转

标签: apk布局androidimageview页面跳转
336人阅读 评论(0) 收藏 举报
分类:
/**
 * 
 * @author Administrator
 *BMI计算器
 *重点:数据传递,界面切换菜单设置
 *单键按键监听(XML中设置)
 */
public class MainActivity extends Activity {
EditText height,wei;
Button comp,clear;
double heightDouble,weiDouble,bmi;
String heightString,weiString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
height=(EditText)findViewById(R.id.height);
wei=(EditText)findViewById(R.id.wei);
comp=(Button)findViewById(R.id.comp);
clear=(Button)findViewById(R.id.clear);
}
public void clear3(View v){
height.setText("");
wei.setText("");
}
public void comp(View v){
heightString=height.getText().toString();
weiString=wei.getText().toString();
if(heightString.equals("")||weiString.equals(""))
{
Toast.makeText(MainActivity.this, "身高或体重不能为空",Toast.LENGTH_LONG).show();
}
else{
heightDouble = Double.parseDouble(height.getText().toString());
weiDouble = Double.parseDouble(wei.getText().toString());
bmi=weiDouble/(heightDouble*heightDouble);
Intent intent=new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("bmi",bmi );
intent.putExtra("height", heightDouble);
startActivity(intent);
finish();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
 // TODO Auto-generated method stub
//  return super.onOptionsItemSelected(item);
 super.onOptionsItemSelected(item);
 switch(item.getItemId())
 {
 case R.id.close:
 System.exit(0);
     break;
 }
 return true;
}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:25048次
    • 积分:638
    • 等级:
    • 排名:千里之外
    • 原创:45篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条