My question is:
Is there any way to prevent the click of a button if an EditText has no number? I was able to limit minimum and maximum values (0 to 255), but I could not find a solution to this problem. Because "" is not an integer value, by clicking the button without filling in the three fields with any number, the app crashes.
I tried to use this medium, but I did not succeed:
btnCalc.setOnClickListener (new View.OnClickListener()
{
public void onClick(View v)
{
if (edtRed == null || edtGreen == null || edtBlue == null)
{
btnCalc.setEnabled(false);
}
else
{
btnCalc.setEnabled(true);
getCode();
}
if (n1 > 255 || n1 < 0 || n2 > 255 || n2 < 0 || n3 > 255 || n3 < 0)
{
result = "#FFFFFF";
txtResult.setText(result);
}
else
{
Calculate();
}
result = "#" + rst1 + remainderR + rst2 + remainderG + rst3 + remainderB;
txtResult.setText(result);
}
});