android - How can I launch a event when I check or uncheck CheckBoxPreference in PreferenceScreen? -


i hope execute function when check or uncheck checkboxpreference in preferencescreen, how can ? thanks!

<preferencescreen xmlns:android="http://schemas.android.com/apk/res/android"     android:key="apppreference"     android:summary="@string/preferencesummary"     android:title="@string/preference" >       <checkboxpreference         android:defaultvalue="true"         android:key="alwayshideicon"         android:title="@string/alwayshideicontitle"         android:summary="@string/alwayshideiconsummary"           android:layout="@layout/sms_custom_preference_layout"        />     </preferencescreen>  public class smspreference extends preferenceactivity{      @override      protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);                      addpreferencesfromresource(r.xml.smspreference);             setcontentview(r.layout.sms_custom_preference);              // adview resource , load request.             if (publicpar.isregistered==false) {                 adview adview = (adview)this.findviewbyid(r.id.adview);                 adview.loadad(new adrequest());             }               button btnclose=(button)findviewbyid(r.id.btnclosepreference);             btnclose.setonclicklistener(new onclicklistener(){                 @override                 public void onclick(view v) {                     // todo auto-generated method stub                     finish();                 }                        });       }  }  <relativelayout   xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"      android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:background="@drawable/border_ui"   android:orientation="vertical">              <listview android:id="@android:id/list"         android:layout_width="fill_parent"          android:layout_height="wrap_content"         android:layout_below="@+id/adview"             android:layout_above="@+id/linearlayout1"         >             </listview>       <linearlayout         android:id="@+id/linearlayout1"           android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_gravity="center_vertical"         android:gravity="center"         android:orientation="horizontal"         android:weightsum="4" >          <button             android:id="@+id/btnclosepreference"             style="@style/mytextappearance"             android:layout_width="0dip"             android:layout_height="fill_parent"             android:layout_weight="1"             android:layout_gravity="center"             android:text="@string/btnreturn" >         </button>     </linearlayout> </relativelayout> 

    checkboxpreference preference = (checkboxpreference) findpreference("preference");     preference.setonpreferencechangelistener(new preference.onpreferencechangelistener()      {          public boolean onpreferencechange(preference preference, object newvalue)          {             log.d("myapp", "pref " + preference.getkey() + " changed " + newvalue.tostring());              if(newvalue.tostring().equalsignorecase("true"))                 //here manage event checked preference             else                 //here manage event unchecked preference              return true;         }     }); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -