0

내가 checkboxpreferences.This를 통해 내 서비스를 중지 할 수는 CheckBoxPreference 코드를 체크 박스는 서비스가 중지 선택하지 않은 아무것도 일어나지 않을 것이다 그래서 경우이유는 서비스를 중지 할 수 없습니다?

CheckBoxPreference checkBoxPref = (CheckBoxPreference) getPreferenceManager().findPreference("firstDependent"); 
     checkBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {    
       public boolean onPreferenceChange(Preference preference, Object newValue) { 
        if (newValue.toString().equals("true")) { 
         editor.putBoolean("notification_a", true); 
         editor.commit(); 
         //sendSimpleNotification(); 
         startService(new Intent(settings.this,service.class)); 
         Log.d("Check", "startService from checkbox"); 

        } 
        else if (newValue.toString().equals("false")){ 
         editor.putBoolean("notification_a", false); 
         editor.commit(); 
        //mNotificationManager.cancel(SIMPLE_NOTIFICATION_ID); 
         stopService(new Intent(getApplicationContext(),service.class)); 
         Log.d("Check", "stopService from checkbox"); 
        } 
        return true; 
       } 
     }); 

입니다. 이유는 무엇입니까?

답변

1
public class YOUR_CLASS extends Activity implements View.OnClickListener{ 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.pianostudio); 
...CODE... 
    CheckBox checkBoxPref = (CheckBox)findViewById(R.id.YOUR_CHECKBOX_ID); 
    checkBoxPref.setOnClickListener(this); 
...OTHER CODE... 
} 


@Override 
public void onClick(View v) { 
    switch(v.getId()){ 
     case R.id.YOUR_ID_CHECKBOX:{  //checkbox per de/selezionare l'idoneita' di un esame 
      if (checkBoxPref.isChecked()){ 
       editor.putBoolean("notification_a", true); 
       editor.commit(); 
       //sendSimpleNotification(); 
       startService(new Intent(settings.this,service.class)); 
       Log.d("Check", "startService from checkbox");; 
      } 
      else{ 
       editor.putBoolean("notification_a", false); 
       editor.commit(); 
       //mNotificationManager.cancel(SIMPLE_NOTIFICATION_ID); 
       stopService(new Intent(getApplicationContext(),service.class)); 
       Log.d("Check", "stopService from checkbox"); 
      } 
      break; 
     } 
    } 
} 
} 
+0

이탈리아어 Oro..scusa하지만'checkBoxPref.setOnClickListener (이);?'내가 넣어 nell'onCreate? –

+0

어쨌든 왜 내 방법해야하지? CheckBoxPreference가 사용하는 이유 –

+0

이해가 안 돼요? 당신이 필요로하는 모든 내가 당신에게 한 방법을 체크 박스 청취자 인 경우 훨씬 더 쉽습니다. 나는이 사용 CheckBoxPreference screen..per 내 취향이다 settings.java에서 오전 왜 업데이트 된 코드 –

관련 문제