I need some spinner help. I have three spinners, as seen in the XML screenshot I uploaded, that I need to be able to get values from for use in a formula. The formula is
MSF cost = 1000/(width/12*length) * Thickness
The values of width, length, and thickness are selectable in spinners of the same name.
I do not know, and have not found a good guide online, for being able to take the selected spinner value and put it into a variable to use in the above formula.
public class Rotary extends Activity {
private double rollCost; // Entered Price of the Roll
private double thickness; // selected thickness
private double width; // selected width
private double length; // selected length
private double MSF; //square foot price
EditText total; // textbox to show total value
EditText rollPrice; //Textbox for entering price
Spinner slength;
Spinner swidth;
Spinner sthick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rotary);
rollPrice = (EditText) findViewById(R.id.RollPrice);
total = (EditText) findViewById(R.id.total);
sthick = (Spinner) findViewById(R.id.Thick_spinner);
swidth = (Spinner) findViewById(R.id.Width_spinner);
slength = (Spinner) findViewById(R.id.length_spinner);
//rollPrice.addTextChangedListener(rollPriceListener);
swidth = (Spinner) findViewById(R.id.Width_spinner);
sthick = (Spinner) findViewById(R.id.Thick_spinner);
slength = (Spinner) findViewById(R.id.length_spinner);
TextWatcher rollPriceListener = new TextWatcher(){
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
try{
// Change the billBeforeTip to the new input
rollCost = Double.parseDouble(arg0.toString());
}
catch(NumberFormatException e){
rollCost = 0.0;
}
};
};