Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public void onClick(View view){
  2. int id=view.getId();
  3. switch (id){
  4. case R.id.btnResult:
  5. if(edWeight.length()==0 || edHeight.length()==0){
  6. Toast.makeText(MainActivity.this,"輸入數字",Toast.LENGTH_LONG).show();
  7. return;
  8. }
  9. double height=Double.parseDouble(edHeight.getText().toString());
  10. double weight=Double.parseDouble(edWeight.getText().toString());
  11.  
  12. Intent intent=new Intent(MainActivity.this,ResultActivity.class);
  13. Bundle bundle=new Bundle();
  14. bundle.putDouble("height",height);
  15. bundle.putDouble("weight",weight);
  16. intent.putExtras(bundle);
  17. //只傳送資料
  18. //startActivity(intent);
  19.  
  20. //傳送資料並準備接受回傳資料
  21. startActivityForResult(intent,BMI_REQUEST_CODE);
  22.  
  23. break;
  24. case R.id.btnCls:
  25. edHeight.setText("");
  26. edWeight.setText("");
  27. edHeight.requestFocus();
  28.  
  29. ivResult.setVisibility(View.GONE);//讓預設藏起來的圖片也不見
  30. break;
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement