What is the method is to assign a default value in edittext? Like if user did not enter any value how to perform the required task by default value.
int hft=Integer.parseInt(takehtft.getText().toString());
int hin=Integer.parseInt(takehtin.getText().toString());
This is a simple code to take the height(in feet)and the height(in inch).
How to calculate the total height in feet if the user did not enter the inch height, by assuming the value of hin=0?
3
Answers
You can auto-fill the inch edit text with a 0 value in onCreate.
takehtin.setText("0");
or you can check for
takehtin.getText().isEmpty()
if it is empty set the inch value to 0
Try setting default value in XML file :-
Check if edittext’s are empty, then don’t assign any value: