Kagan Inan
Kagan Inan

Reputation: 15

Android - How to get float values and control?

I have two editText. First edit text is amount, second edit text is description. I get the amunt edit text values float, description edit text values string. But error when control values. I think wrong "(tutarEdit.getText().toString().equals("")".

Thanks in Advance..

final EditText tutarEdit = (EditText) layout.findViewById(R.id.editTextTutar);
final EditText aciklamaEdit = (EditText) layout.findViewById(R.id.editTextAciklama);

Float tutar = Float.parseFloat(tutarEdit.getText().toString());
String aciklama = aciklamaEdit.getText().toString();

if(tutarEdit.getText().toString().equals("") || aciklamaEdit.getText().toString().equals("")){
                        Toast.makeText(MainActivity.this, "Void", Toast.LENGTH_LONG).show();                        
}

Upvotes: 1

Views: 319

Answers (1)

Faisal
Faisal

Reputation: 2276

You are getting parse error when tutarEdit is "", surround it with try/catch

Float tutar = 0;
try {
    tutar = Float.parseFloat(tutarEdit.getText().toString());
} catch (Exception e) {
    e.printStackTrace();
}

Upvotes: 2

Related Questions