Lemans Trương
Lemans Trương

Reputation: 1

How to use setIs24HourView(boolean)?

I have a problem here. I try to make a new alarm here.

I want to toggle TimePicker View mode between 12h mode and 24h mode. So I try to create a new public var and the return value method like this

public class AlarmSettings extends Activity {

public static boolean is24h=false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alarm_settings);
    CheckBox cb24h;
    cb24h = (CheckBox) findViewById(R.id.checkbox_24h);
    cb24h.setChecked(true);
}

public boolean getState24()
{
    return true;
}}

And when I call it in the another class:

if (id == -1) {
        alarmDetails = new AlarmModel();
    } else {
        alarmDetails = dbHelper.getAlarm(id);
        AlarmSettings as = null;
        boolean is24h = as.getState24();
        if(is24h==true)
            timePicker.setIs24HourView(true);
        else
            timePicker.setIs24HourView(false);

        timePicker.setCurrentMinute(alarmDetails.timeMinute);
        timePicker.setCurrentHour(alarmDetails.timeHour);

But, it changes nothing! Can you guys show me what's wrong here?

Upvotes: 0

Views: 141

Answers (1)

Damien Diehl
Damien Diehl

Reputation: 382

public boolean getState24()
{
    return true;
}

This always returns true, make it return the value of is24h.

Upvotes: 1

Related Questions