Get checkbox status as soon as it is checked or unchecked
<p>I want to get the current status of checkbox as soon as it is check or unchecked. Based on that show the Toast message. Here is my code so far.</p>

<pre><code>SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean Alarm = getPrefs.getBoolean("cbAlarm", true);
    if(Alarm == true) {
        Toast.makeText(this, "Checked", Toast.LENGTH_LONG).show();
    } else if(Alarm == false) {
        Toast.makeText(this, "UnChecked", Toast.LENGTH_LONG).show();
    }
</code></pre>

<p>How can I achieve this. Please help.</p>

<p><strong>Edit</strong>
here is my xml file</p>

<pre><code>&lt;CheckBoxPreference
    android:title="Enable/Disable Alarm"
    android:defaultValue="true"
    android:key="cbAlarm"
    android:summary="Enable or disable alarm" /&gt;
</code></pre>
