Android : Android if-else statement not functioning correctly

on Wednesday, July 30, 2014


The purpose of this app is the take a editText that would be an acronym and show what it means. (e.g. lol is laugh out loud) the problem is no matter what i input it always returns the else statement of "none found" program compiles fine. Thanks for your help!!



// Define Variables
EditText et1;
TextView tv1;
Button button;
String acronym;
String lol,omg;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);

et1=(EditText) findViewById(R.id.editText);
tv1=(TextView) findViewById(R.id.textView);
button=(Button) findViewById(R.id.button);
acronym=et1.getText().toString().toLowerCase();


button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

if (acronym.equals(lol)) {
tv1.setText("lol means laugh out loud");
} else if(acronym.equals(omg)) {
tv1.setText("omg means oh my god");
} else {
tv1.setText("none found.");
}
}
});
}

0 comments:

Post a Comment