How do I work with LONG "data" inserted in an editText?

0

I tried to pass numbers that would be inserted into 3 editTexts for 3 long variables I created: l01, l02, l03 . In order to work them out and make a very simple account.

MainActivity.java:

package genesysgeneration.treerule;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class MainMenuActivity extends AppCompatActivity {

    private EditText et01, et02, et03;
    private TextView tv01;
    private long l01, l02, l03;

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

        l01=0;
        l02=0;
        l03=0;

        et01=(EditText)findViewById(R.id.et01);
        et02=(EditText)findViewById(R.id.et02);
        et03=(EditText)findViewById(R.id.et03);

        l01=et01;
        l02=et02;
        l03=et03;

        tv01=(TextView)findViewById(R.id.tv01);
        tv01.setText(l01*l02*l03);

    }
}

I also changed the 3 inputType of the 3 editTexts to number | numberDecimal :

What did I do wrong, or what did I fail to do? The program did not even run errors in the following lines:

l01=et01;
l02=et02;
l03=et03;

tv01.setText(l01*l02*l03);
    
asked by anonymous 26.01.2017 / 01:06

1 answer

1

First, you should use the getText method to get the values of the EditText fields and convert to Long :

l01 = Long.parseLong(et01.getText().toString());
l02 = Long.parseLong(et02.getText().toString());
l03 = Long.parseLong(et03.getText().toString());

The setText method accepts a parameter of type CharSequence . You can do a String conversion:

tv01.setText(String.valueOf(l01 * l02 * l03));
    
26.01.2017 / 01:31