This is an android java code. eEmi, eLoss, eMonth, eMembers are EditText and the app has submit and reset button. The problem is that the else part in the code is always executing. What I want here is that the user should not leave any EditText empty, if he leaves anyone empty, it should display a toast notification. What is wrong in the code? and is there any other way to do this efficiently?
eEmi = (EditText) findViewById(R.id.emi);
eMembers = (EditText) findViewById(R.id.members);
eLoss = (EditText) findViewById(R.id.loss);
eMonth = (EditText) findViewById(R.id.month);
submit = (Button) findViewById(R.id.Bsubmit);
reset = (Button) findViewById(R.id.Breset);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (eEmi.getText().toString() == null
&& eMembers.getText().toString() == null
&& eLoss.getText().toString() == null
&& eMonth.getText().toString() == null) {
emi = Double.valueOf(eEmi.getText().toString());
members = Double.valueOf(eMembers.getText().toString());
loss = Double.valueOf(eLoss.getText().toString());
month = Double.valueOf(eMonth.getText().toString());
Intent submit = new Intent(MainActivity.this,
ResultActivity.class);
submit.putExtra("emi", emi);
submit.putExtra("members", members);
submit.putExtra("loss", loss);
submit.putExtra("month", month);
startActivity(submit);
} else {
Toast.makeText(MainActivity.this, R.string.invalid, Toast.LENGTH_SHORT).show();
}
}
});