EditText edit = (EditText)findViewByid(R.id.edit); //estabeleço o conexão
if(edit.getText().toString().isEmpty()){ // verificando se a edit esta vazia
String num = "6"; // Ou use um int, não vejo necessidade de ser um double
edit.setText(num); //inserindo valor na edit
}
// code above works
// This is not below
// method calling by class public class Temperature {
public double getFaRetorneCels(double cel){
return ((cel*9)/5)+32;
}
public double getCelRetorneFa(double fah){
return ((fah-32)*5/9);
}
}
// button code
public void convert (View view) { EditText edtcel = (EditText) findViewById (R.id.edtCel); EditText edtfa = (EditText) findViewById (R.id.ediFa);
Temperatura t = new Temperatura();
double c = Double.parseDouble(edtcel.getText().toString());
double f = Double.parseDouble(edtfa.getText().toString());
if(edtcel.getText().toString().isEmpty() && edtfa.getText().toString().isEmpty() ){
Toast.makeText(this,"Pelo menos um campo deve ser preenchido!!!",Toast.LENGTH_SHORT).show();
}else if(edtcel.getText().toString().isEmpty()) {
edtcel.setText(String.valueOf(t.getCelRetorneFa(f)));
}else if (edtfa.toString().isEmpty()){
edtfa.setText(String.valueOf(t.getFaRetorneCels(c)));
}
If anyone can help thank you