I am trying to display the result of a calculation on a TextView
or EditText
. I get the users input from one100lbs and tenPounds and then add it together and am trying to display it on totalPounds. Its is not the equation I am going to use but just want to see that it works. Currently with the code below my application crashs. This is all under one activity
. Also how come when I change the ID of a EditText
the location of the editText
changes on my relative layout
? Please no links, i know its simple but I am a noob. I have searched and am having a hard time finding a solution.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pounds);
addListenerOnSpinnerItemSelection();
EditText one100lbs = (EditText) findViewById(R.id.one100lbs);
int one = Integer.valueOf(one100lbs.getText().toString());
EditText tenPounds = (EditText) findViewById(R.id.tenPounds);
int two = Integer.valueOf(tenPounds.getText().toString());
int result = one + two;
TextView textView = (TextView) findViewById(R.id.totalPounds);
textView.setText(result);
}