android - Can't get the editText integer value right -
i'm new programming don't know how fix or why it's happening.
i'm making app , in main2activity it's suppose user insert value in edittext , then, after user presses button, value turn integer , used in mathematical operation.
the thing is, when try out, when press button in mainactivity take me main2activity, app crashes.
i narrowed problem coding have in button main2activity don't know what's wrong.
this main2activity code. can me? thanks.
package com.example.cabr.teste; import android.content.intent; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class main2activity extends appcompatactivity { public double valorhorasponta = 0; public double valorhorascheias = 0; public double valorhorasvazio = 0; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main2); textview textview9 = (textview) findviewbyid(r.id.textview9); textview textview10 = (textview) findviewbyid(r.id.textview10); textview textview12 = (textview) findviewbyid(r.id.textview12); textview textview14 = (textview) findviewbyid(r.id.textview14); final textview textview11 = (textview) findviewbyid(r.id.textview11); final textview textview13 = (textview) findviewbyid(r.id.textview13); final textview textview15 = (textview) findviewbyid(r.id.textview15); final textview textview17 = (textview) findviewbyid(r.id.textview17); final edittext edittext1 = (edittext) findviewbyid(r.id.edittext1); final edittext edittext2 = (edittext) findviewbyid(r.id.edittext2); final edittext edittext3 = (edittext) findviewbyid(r.id.edittext3); final edittext edittext4 = (edittext) findviewbyid(r.id.edittext4); button button = (button) findviewbyid(r.id.button); intent = getintent(); string valorpot1 = i.getstringextra("valorpot1"); string valorpot12 = i.getstringextra("valorpot12"); textview9.settext(valorpot1); if (valorpot12.equals("tarifas de médias utilizações")){ valorhorasponta = 0.3128; textview10.settext(string.valueof(valorhorasponta)); valorhorascheias = 0.1555; textview12.settext(string.valueof(valorhorascheias)); valorhorasvazio = 0.0862; textview14.settext(string.valueof(valorhorasvazio)); } if (valorpot12.equals("tarifas de longas utilizações")){ valorhorasponta = 0.2318; textview10.settext(string.valueof(valorhorasponta)); valorhorascheias = 0.1341; textview12.settext(string.valueof(valorhorascheias)); valorhorasvazio = 0.08; textview14.settext(string.valueof(valorhorasvazio)); } button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string valorquantponta1 = edittext1.gettext().tostring(); int valorquantponta = integer.parseint(valorquantponta1); string valorquantcheias1 = edittext2.gettext().tostring(); int valorquantcheias = integer.parseint(valorquantcheias1); string valorquantvazio1 = edittext3.gettext().tostring(); int valorquantvazio = integer.parseint(valorquantvazio1); string valorquantpot1 = edittext4.gettext().tostring(); int valorquantpot = integer.parseint(valorquantpot1); double valortotponta = valorhorasponta * valorquantponta; double valortotcheias = valorhorascheias * valorquantcheias; double valortotvazio = valorquantvazio * valorhorasvazio; textview11.settext(string.valueof(valortotponta)); textview13.settext(string.valueof(valortotcheias)); textview15.settext(string.valueof(valortotvazio)); } }); } }
you can take value edittext in way
edittext edittext=(edittext)findviewbyid(r.id.edittext);
string string=edittext.gettext().tostring;
int int_value_from_edittext=integer.parseint(string);
Comments
Post a Comment