• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

My first app - getting input values

Greum

Well-Known Member
Hi

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 {

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

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) {
doCalculations();
}
});
}

void doCalculations() {
Log.i("info", "In doCalculations");
// get inputs ** this is where I'm stuck **
}
}
 
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!
 
Back
Top Bottom