2011-10-02 2 views
0

알람 및 타이머 응용 프로그램에서 사운드 선택과 비슷한 방식으로 사운드 환경 설정을 만들고 싶습니다. 간단히 말해, 선호도는 표준 목록 선호도로 시작하지만 일단 음악 또는 벨소리 선택이 이루어지면 다른 대화 상자가 표시되어 오디오를 선택할 수 있습니다.단일 환경 설정에서 두 개의 대화 상자를 사용하는 방법

맞춤 환경 설정 처리기를 만드는 유일한 방법은 무엇입니까? 초기 목록 환경 설정 변경 사항을 캡처 한 다음 오디오 처리기를 표시 할 수 있습니까?

답변

0

여기 내 해결책이 있습니다. 나는 내 자신의 클래스로 ListPreference를 확장했다. 대화 상자가 닫히면 오디오 목록 용 선택기가 호출됩니다. 선택이 완료되면 사용자 정의, 상위 PreferenceActivity가 호출됩니다.

관련 코드 비트 :

public class AlertBehaviorPreference extends ListPreference { 
... 
    public void onDialogClosed(boolean positiveResult) 
    { 
     super.onDialogClosed(positiveResult); 
     if(positiveResult) 
     { 
      String s = this.getValue(); 
      if(s != null && s.equals(SONG_ALARM_ACTION)) // play song 
      { 
       // Get the parent activity. 
       // This activity will be notified when the audio has been selected 
       PreferenceActivity pActivity = (PreferenceActivity)this.getContext(); 

       // Select a recording 
       Intent i = new Intent(pActivity, pActivity.getClass());   
       i.setAction(Intent.ACTION_GET_CONTENT); 
       i.setType("audio/*"); 
       pActivity.startActivityForResult(Intent.createChooser(i, "Select song"), 1); 

       Log.d(TAG, "Started audio activity chooser"); 
      } 

public class MyPreferenceActivity extends PreferenceActivity { 
... 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     // Call back into the preference to save data 
     // Where the result can be validated and settings can be 
     // be reset if the user cancelled the request. 
     ((AlertBehaviorPreference)(findPreference("alertBehaviorPreference"))).onSongActivitySelectionComplete(data); 
    } 
관련 문제