I'm following a tutorial to make an application and the calculate button does not work for me. This button, when indicating a quantity in the inputBill and clicking on the button should leave me a text with the calculated tip, but it does not do anything.
then my elements in the layout.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="@string/main.hint.bill"
android:ems="10"
android:id="@+id/inputBill"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main.button.submit"
android:id="@+id/btnSubmit"
android:layout_alignParentTop = "true"
android:layout_toRightOf="@+id/inputBill"
android:layout_toEndOf="@+id/inputBill"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/txtTip"
android:layout_below="@id/separator"
android:visibility="gone"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
I leave the code I have so far,
@BindView(R.id.inputBill)
EditText inputBill;
@BindView(R.id.btnSubmit)
Button btnSubmit;
@BindView(R.id.inputPercentage)
EditText inputPercentage;
@BindView(R.id.btnIncrease)
Button btnIncrease;
@BindView(R.id.btnDecrease)
Button btnDecrease;
@BindView(R.id.btnClear)
Button btnClear;
@BindView(R.id.separator)
View separator;
@BindView(R.id.txtTip)
TextView txtTip;
private final static int TIP_STEP_CHANGE = 1;
private final static int DEFAULT_TIP_PERCENTAGE = 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
@OnClick(R.id.btnSubmit)
public void handleClickSubmit() {
// hideKeyBoard();
String strInputTotal = inputBill.getText().toString().trim();
if (!strInputTotal.isEmpty()) {
double total = Double.parseDouble(strInputTotal);
int tipPercentage = getTipPercentage();
double tip = total * (tipPercentage / 100d);
String strTip = String.format(getString(R.string.global_message_tip), tip);
// log.d("no se crea la variable strtip");
Log.d("txtTip", "error encontrado");
txtTip.setVisibility(View.VISIBLE);
txtTip.setText(strTip);
}
}
I do not have errors in the code, compile but something wrong I'm doing and I do not know ...
Hello, I'll show you the screenshot of the logcat. one of the errors that I had session 'app' error lauching activity no longer I have it when deactivating in settings the auto run ....