1. Are you ready for the Galaxy S20? Here is everything we know so far!

My first app - getting input values

Discussion in 'Android Development' started by Greum, Jun 2, 2019.

  1. Greum

    Greum Well-Known Member
    Thread Starter


    I am new to Android development (but not to development).

    I have read most of Android Programming for Beginners 2nd edition by John Horton, and I have Android Studio v. 3.4.1.

    I am trying to create my first app. My app will take a couple of input figures, do some calculations and provide a result.

    I have the layout and I have started on the code and it all works as far as it goes, but I am struggling to fathom out how to get the input values to use in the calculations.

    This is my code. Can anyone help, please? Thanks.

    package domain.com.myfirstapp;

    import androidx.appcompat.app.AppCompatActivity;

    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.EditText;

    public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

    final EditText editSPrice = (EditText) findViewById(R.id.editText2);
    final EditText editPPrice = (EditText) findViewById(R.id.editText3);

    Button button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {

    void doCalculations() {
    Log.i("info", "In doCalculations");
    // get inputs ** this is where I'm stuck **

  2. Greum

    Greum Well-Known Member
    Thread Starter

    Hah. I seem to have found the answer. I had put the 2 final EditText statements in the wrong block.

    Nothing like posting a query on a forum for finding the answer!
    23tony likes this.

Share This Page