Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. package com.klinetel.bac.calculator;
  2.  
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.app.AlertDialog;
  6. import android.view.View;
  7. import android.widget.*;
  8. import android.content.*;
  9.  
  10.  
  11. public class MainActivity extends Activity {
  12.  
  13. RadioGroup group1;
  14. RadioButton maleRadio, femaleRadio;
  15. // Button button = (Button)findViewById(R.id.button1);
  16.  
  17. @Override
  18. public void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_main);
  21.  
  22. AlertDialog.Builder alert = new AlertDialog.Builder(this);
  23. alert.setTitle("The Result");
  24. alert.setMessage("Your Blood Alcohol Content Percentage is:");
  25. alert.setPositiveButton("OK", null);
  26. alert.create().show();
  27.  
  28.  
  29. Button button = (Button)findViewById(R.id.button1);
  30. button.setOnClickListener(new View.OnClickListener(){
  31.  
  32. @Override
  33. public void onClick(View view)
  34. {
  35. Intent intent = new Intent(view.getContext(),ResultsActivity.class);
  36. startActivityForResult(intent,0);
  37. finish();
  38.  
  39. }
  40.  
  41. });
  42. }
  43.  
  44.  
  45.  
  46. //Input conversion-to-string-attributes
  47. public void calcBAC(){
  48.  
  49. //weight
  50. EditText editWeight = (EditText)findViewById(R.id.editText1);
  51. double weight = Double.parseDouble(editWeight.getText().toString());
  52.  
  53. //hours
  54. EditText editHours = (EditText)findViewById(R.id.editText2);
  55. double hours = Double.parseDouble(editHours.getText().toString());
  56.  
  57. //drinks
  58. EditText editDrinks = (EditText)findViewById(R.id.editText3);
  59. double drinks = Double.parseDouble(editDrinks.getText().toString());
  60.  
  61. //radio buttons
  62. maleRadio=(RadioButton)findViewById(R.id.radio0);
  63.  
  64. femaleRadio=(RadioButton)findViewById(R.id.radio1);
  65.  
  66.  
  67. //bac total
  68. double resultBAC=0;
  69.  
  70. //male formula
  71. if(maleRadio.isChecked()){
  72.  
  73. resultBAC=(((EQUATION HERE))/2;
  74.  
  75. }
  76. //female formula
  77. else if(femaleRadio.isChecked()){
  78.  
  79. resultBAC=(((EQUATION HERE))/2;
  80. }
  81.  
  82. }
  83.  
  84.  
  85. }
  86.  
  87. package com.klinetel.bac.calculator;
  88.  
  89. import android.os.Bundle;
  90. import android.app.Activity;
  91. import android.view.*;
  92. import android.widget.*;
  93. import android.content.Intent;
  94.  
  95.  
  96. public class ResultsActivity extends Activity {
  97.  
  98. @Override
  99. public void onCreate(Bundle savedInstanceState) {
  100. super.onCreate(savedInstanceState);
  101. setContentView(R.layout.activity_results);
  102.  
  103.  
  104. TextView result;
  105.  
  106. Button button = (Button)findViewById(R.id.backButton);
  107.  
  108. button.setOnClickListener(new View.OnClickListener(){
  109.  
  110. @Override
  111. public void onClick(View view)
  112. {
  113. Intent intent = new Intent(view.getContext(),MainActivity.class);
  114. startActivityForResult(intent,0);
  115. finish();
  116.  
  117. }
  118.  
  119.  
  120. });
  121. result=(TextView)findViewById(R.id.textView1);
  122. //result=resultBAC.getValue;
  123. }
  124. }
  125.  
  126. Intent intent = new Intent(view.getContext(),ResultsActivity.class);
  127. intent.putExtra("extraname", "extravalue");
  128. intent.putExtra("extraname2", 9.99);
  129. startActivityForResult(intent,0);
  130. finish();
  131.  
  132. @Override
  133. public void onCreate(Bundle savedInstanceState) {
  134. super.onCreate(savedInstanceState);
  135. setContentView(R.layout.activity_results);
  136. String extra = getIntent().getStringExtra("extraname") //returns null if nothing
  137. Double extra2 = getIntent().getDoubleExtra("extraname2")
  138.  
  139. Bundle extras = getIntent().getExtras();
  140. if (extras != null)
  141. {
  142. username = extras.getString("username");
  143. password = extras.getString("password");
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement