First off, I’m a beginner at this… so if what I’m doing is pretty simple to fix (or do in general), I apologize 🙂
I’m trying to take user inputs (laps [int], fuel used [double], and laps of a feature [int]) to create a simple fuel calculator for racers. However, I’m having trouble getting the variables to recognize. I keep getting errors about I’m unable to use one function in a certain class and things like that. I’ve got the XML fields assigned to only take those types of numbers, so now I’m working strictly in the java.
I had the thing working in the java compiler, but taking it to Android is a whole other process I’m learning.
After calculating from the user inputs, I want the assigned textView to change to the proper answers. I think that part is ok, but getting the values to mathematically-viable values is where I’m running into a problem.
I’ve attached the entire code here (pardon the redundancy with comments, keeps me from looking back and forth for the formula haha). Any help you can provide would be appreciated! I’ll do my best to learn from it for the other math-related activities in this app.
package com.tomcat.carolina.learning;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
//double pracLaps, fuelUsed, featureLaps, textLPGValue, textFuelNeededValue;
public class Fuelsimple extends Activity implements OnClickListener{
EditText fuelUsed, pracLaps, featureLaps;
TextView textLPGValue, textFuelNeededValue;
//efficiency = (pracLaps / fuelUsed);
//fuelNeeded = (featureLaps / efficiency);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fuelsimple);
pracLaps = (EditText) findViewById(R.id.pracLaps);
fuelUsed = (EditText) findViewById(R.id.fuelUsed);
featureLaps = (EditText) findViewById(R.id.featureLaps);
Button gen = (Button) findViewById(R.id.submit);
textLPGValue = (TextView) findViewById(R.id.textLPGvalue);
textFuelNeededValue = (TextView) findViewById(R.id.textFuelNeededValue);
gen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
textLPGValue.setText(getNextDecimal(pracLaps / fuelUsed));
textFuelNeededValue.setText(getNextDecimal(featureLaps/(pracLaps / fuelUsed)));
};
});
I hope this is what you are looking for: