0

Yes I have been thru several questions on this topic. It's about the setText on a textWatcher field. I am quite new to all this and maybe that's why Haven't been able to apply a good fix. I am not much of a explaining type so... Here is my code:

package com.newera.speedsnfeeds;

import java.math.BigDecimal;
import java.math.RoundingMode;



import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
 import android.widget.EditText;

public class Main1Activity extends Activity implements TextWatcher {

private EditText dia, sfm, rpm,flutes,load,feed;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main1);

    dia = (EditText) findViewById(R.id.dia);
    dia.addTextChangedListener(this);

    sfm = (EditText) findViewById(R.id.sfm);
    sfm.addTextChangedListener(this);

    rpm = (EditText) findViewById(R.id.rpm);
    rpm.addTextChangedListener(this);

    flutes = (EditText) findViewById(R.id.flutes);
    flutes.addTextChangedListener(this);

    load = (EditText) findViewById(R.id.load);
    load.addTextChangedListener(this);

    feed = (EditText) findViewById(R.id.feed);
    feed.addTextChangedListener(this);




    rpm.setText("1");

    feed.setText("");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {
    // TODO Auto-generated method stub

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    // TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable s) {
    // TODO Auto-generated method stub
    calculate();

}








@SuppressLint("UseValueOf")
private void calculate() {

    if (dia.getText().toString().compareTo("") == 0
            || sfm.getText().toString().compareTo("") == 0
            || rpm.getText().toString().compareTo("") == 0
            ||flutes.getText().toString().compareTo("") == 0
            ||load.getText().toString().compareTo("") == 0)

    {

        //rpm.setText("1");

        //feed.setText("1");




    }else{
        if (dia.getText().toString().compareTo(".") == 0
                || dia.getText().toString().compareTo("-") == 0
                || dia.getText().toString().compareTo("-0") == 0
                || dia.getText().toString().compareTo("-00") == 0
                || dia.getText().toString().compareTo("-000") == 0
                || dia.getText().toString().compareTo("-0000") == 0
                || dia.getText().toString().compareTo("-.") == 0


                || sfm.getText().toString().compareTo(".") == 0
                || sfm.getText().toString().compareTo("-") == 0
                || sfm.getText().toString().compareTo("-0") == 0
                || sfm.getText().toString().compareTo("-00") == 0
                || sfm.getText().toString().compareTo("-000") == 0
                || sfm.getText().toString().compareTo("-0000") == 0
                || sfm.getText().toString().compareTo("-.") == 0

                || rpm.getText().toString().compareTo("-") == 0
                || rpm.getText().toString().compareTo("-0") == 0
                || rpm.getText().toString().compareTo("-00") == 0
                || rpm.getText().toString().compareTo("-000") == 0
                || rpm.getText().toString().compareTo("-0000") == 0

                || flutes.getText().toString().compareTo("-") == 0
                || flutes.getText().toString().compareTo("-0") == 0
                || flutes.getText().toString().compareTo("-00") == 0
                || flutes.getText().toString().compareTo("-000") == 0
                || flutes.getText().toString().compareTo("-0000") == 0

                || load.getText().toString().compareTo("-") == 0
                || load.getText().toString().compareTo("-0") == 0
                || load.getText().toString().compareTo("-00") == 0
                || load.getText().toString().compareTo("-000") == 0
                || load.getText().toString().compareTo("-0000") == 0

                || feed.getText().toString().compareTo("-") == 0
                || feed.getText().toString().compareTo("-0") == 0
                || feed.getText().toString().compareTo("-00") == 0
                || feed.getText().toString().compareTo("-000") == 0
                || feed.getText().toString().compareTo("-0000") == 0)

        {


            //rpm.setText("1");

            //feed.setText("1");




        } else {
            float diam = Float.valueOf(dia.getText().toString());
            float sfmm = Float.valueOf(sfm.getText().toString());
            float rpmm = Float.valueOf(rpm.getText().toString());
            float flutesm = Float.valueOf(flutes.getText().toString());
            float loadm = Float.valueOf(load.getText().toString());

            BigDecimal trpm = new BigDecimal((sfmm *3.82 / diam));
            trpm = trpm.setScale(0,RoundingMode.UP);

            BigDecimal tfeed = new BigDecimal((rpmm * flutesm * loadm));
            tfeed = tfeed.setScale(1,RoundingMode.UP);




            rpm.setText("1"+ trpm);
            feed.setText("1"+tfeed);



        }


    }



    {



    }

   }


}

It's not done yet I need to have it be able to calculate sfm and load is why it needs to be edit text fields.

I have read other questions on this same problem but they were just different enough of a situation I wasn't able to apply the ideas. probably cause I am so new to programming in general.

Hopefully this is a good way to start a question.

P.S. sorry for the messy code hopefully having the code helps someone show me how to apply a fix to my current code. Also don't hesitate to let me know if this is too unclear or not, need the xml ect.

DLB123
  • 9
  • 4
  • You have the formulas for calculating? also which type of values you would be passsing into edittext? – Arslan Ashraf Nov 25 '15 at 18:31
  • Can you format the code and explain what the problem is? – Iliiaz Akhmedov Nov 25 '15 at 19:23
  • I formatted the code a little better there is still two formulas to add (SFM=.. and Load=..) the issue is where its putting the RPM calculation in that edit text since simply if the user wants to tweak the calculated RPM and see how it affects the SFM and or tweak the calculated feed and see how it affects the load ect. I have a exe that I am copying and eliminate the calculate button for "simplicity". HTH. – DLB123 Nov 27 '15 at 17:04

0 Answers0