Reputation: 11
Ok, first thing is that I am new in Android
development, please do not shoot me for the question.
So, I am developing an app yhat needs to multiply from 3 EditTexts
:
resultsEditText
amountEditText
taxEditText
They are set with the same name in the R.java
. what I want is the following:
amountEditText * taxEditText = resultsEditText
I have no idea in how to implement this, I have searched the internet and this site, which I use as a reference for all my Android development needs, and all the code I found doesnt work at all. I dont know what else to do. Thanks in advance!
Upvotes: 1
Views: 11140
Reputation: 10059
Button btnCal,btnSub;
EditText editLen,editWid,editFeet;
int a,b,res;
btnSub=(Button)findViewById(R.id.btnSub);
btnCal=(Button)findViewById(R.id.btnCal);
editLen=(EditText)findViewById(R.id.editLen);
editWid=(EditText)findViewById(R.id.editWid);
editFeet=(EditText)findViewById(R.id.editFeet);
btnCal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a = Integer.parseInt(editLen.getText().toString());
b = Integer.parseInt(editWid.getText().toString());
res=a*b;
editFeet.setText(String.valueOf(res));
}
});
Upvotes: 0
Reputation: 3966
You need to set EditText input type as number as well so user can input only numbers.
int a = Integer.parseInt(resultsEditText.getText().toString().toTrim());
int b = Integer.parseInt(amountEditText.getText().toString().toTrim());
int c = Integer.parseInt(taxEditText.getText().toString().toTrim());
int result = a * b * c;
Upvotes: 2