여기 내 해결책이 있습니다. 나는 내 자신의 클래스로 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);
}