Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onClick(View view){
- int id=view.getId();
- switch (id){
- case R.id.btnResult:
- if(edWeight.length()==0 || edHeight.length()==0){
- Toast.makeText(MainActivity.this,"輸入數字",Toast.LENGTH_LONG).show();
- return;
- }
- double height=Double.parseDouble(edHeight.getText().toString());
- double weight=Double.parseDouble(edWeight.getText().toString());
- Intent intent=new Intent(MainActivity.this,ResultActivity.class);
- Bundle bundle=new Bundle();
- bundle.putDouble("height",height);
- bundle.putDouble("weight",weight);
- intent.putExtras(bundle);
- //只傳送資料
- //startActivity(intent);
- //傳送資料並準備接受回傳資料
- startActivityForResult(intent,BMI_REQUEST_CODE);
- break;
- case R.id.btnCls:
- edHeight.setText("");
- edWeight.setText("");
- edHeight.requestFocus();
- ivResult.setVisibility(View.GONE);//讓預設藏起來的圖片也不見
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement