我试图让我的 Android 项目通过编辑文本区域检索用户号码。这可能已经在我的代码中完全完成。我不知道如何在方程式中使用捕获的数据,并通过文本框在屏幕上的第二个活动中显示结果。解决方案可能比目前看起来更简单。如果您想要更多的细节和整体信息,请告诉我。
第一项活动:
package com.klinetel.bac.calculator;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.View;
import android.widget.*;
import android.content.*;
public class MainActivity extends Activity {
RadioGroup group1;
RadioButton maleRadio, femaleRadio;
// Button button = (Button)findViewById(R.id.button1);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("The Result");
alert.setMessage("Your Blood Alcohol Content Percentage is:");
alert.setPositiveButton("OK", null);
alert.create().show();
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view)
{
Intent intent = new Intent(view.getContext(),ResultsActivity.class);
startActivityForResult(intent,0);
finish();
}
});
}
//Input conversion-to-string-attributes
public void calcBAC(){
//weight
EditText editWeight = (EditText)findViewById(R.id.editText1);
double weight = Double.parseDouble(editWeight.getText().toString());
//hours
EditText editHours = (EditText)findViewById(R.id.editText2);
double hours = Double.parseDouble(editHours.getText().toString());
//drinks
EditText editDrinks = (EditText)findViewById(R.id.editText3);
double drinks = Double.parseDouble(editDrinks.getText().toString());
//radio buttons
maleRadio=(RadioButton)findViewById(R.id.radio0);
femaleRadio=(RadioButton)findViewById(R.id.radio1);
//bac total
double resultBAC=0;
//male formula
if(maleRadio.isChecked()){
resultBAC=(((EQUATION HERE))/2;
}
//female formula
else if(femaleRadio.isChecked()){
resultBAC=(((EQUATION HERE))/2;
}
}
}
第二个活动:
package com.klinetel.bac.calculator;
import android.os.Bundle;
import android.app.Activity;
import android.view.*;
import android.widget.*;
import android.content.Intent;
public class ResultsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_results);
TextView result;
Button button = (Button)findViewById(R.id.backButton);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view)
{
Intent intent = new Intent(view.getContext(),MainActivity.class);
startActivityForResult(intent,0);
finish();
}
});
result=(TextView)findViewById(R.id.textView1);
//result=resultBAC.getValue;
}
}