@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup4);
    mCheck = (CheckBox) findViewById(R.id.cb_protect);

    boolean protect = mPref.getBoolean("protect", false);
    // 当check发生改变时,回掉此方法
    if (protect) {
      mCheck.setText("防盗保护已经开启");
      mCheck.setChecked(true);
    } else {
      mCheck.setText("防盗保护没有开启");
      mCheck.setChecked(false);
    }
    mCheck.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              mCheck.setText("防盗保护已经开启");
              mPref.edit().putBoolean("protect", true).commit();
            } else {
              mCheck.setText("防盗保护没有开启");
              mPref.edit().putBoolean("protect", false).commit();
            }
          }
        });
  }
Example #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup4);

    initUI();
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_setup2);
   siv_update = (SettingItemView) findViewById(R.id.siv_update);
   tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
   if (!TextUtils.isEmpty(sp.getString("sim", null))) {
     siv_update.setChecked(true);
   } else {
     siv_update.setChecked(false);
   }
   siv_update.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           String sim = tm.getSimSerialNumber(); // 获取sim卡序列号
           SharedPreferences.Editor editor = sp.edit(); // sp sharedpreference在父类已经实现
           // 判断是否选中
           if (siv_update.isChecked()) {
             // 已经选中
             siv_update.setChecked(false);
             editor.putString("sim", null);
           } else {
             // 没选中
             siv_update.setChecked(true);
             editor.putString("sim", sim);
           }
           editor.commit();
         }
       });
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup4);

    cb_setup4_status = (CheckBox) this.findViewById(R.id.cb_setup4_status);
    boolean protecting = sp.getBoolean("protecting", false);
    cb_setup4_status.setChecked(protecting);
    cb_setup4_status.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("protecting", isChecked);
            editor.commit();
          }
        });
  }