I am making an android app for easier time encoding, I programmed it so that whenever I put numbers it outputs time in A.M. and if I put a "p" at the end of those numbers it adds a P.M. at the end.
sat_amin.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
EditText sat_amin = (EditText) findViewById(R.id.asd);
TextView dsa = (TextView) findViewById(R.id.dsa);
String satamin = sat_amin.getText().toString();
int satamln = satamin.length();
String last = satamin.substring(satamin.length() - 1);
String p = "p";
switch(satamln) {
case 1:
sat_amin.setText("12:0" + satamin + " AM");
break;
case 2:
if (last == p) {
sat_amin.setText("12:0" + satamin + " PM");
} else {
sat_amin.setText("12:" + satamin + " AM");
}
break;
case 3:
if (last == p) {
sat_amin.setText("12:" + satamin + " PM");
} else {
sat_amin.setText("0" + satamin.substring(0, 1) + ":" + satamin.substring(1) + " AM");
}
break;
case 4:
if (last == p) {
sat_amin.setText("0" + satamin.substring(0, 1) + ":" + satamin.substring(1, 3) + " PM");
} else {
sat_amin.setText(satamin.substring(0, 2) + ":" + satamin.substring(2) + " AM");
}
break;
case 5:
if (last == p) {
sat_amin.setText(satamin.substring(0, 2) + ":" + satamin.substring(2, 4) + " PM");
} else {
sat_amin.setText(satamin.substring(0, 1) + ":" + satamin.substring(1, 3) + ":" + satamin.substring(3, 5) + " AM");
}
break;
default:
sat_amin.setText("");
break;
}
return false;
}
});
When I run the app the AM part of the code works just fine, but when I add a "p" it doesn't get compared in the if statement and the "p" gets outputted as if the whole string didn't have a "p" in the end.