android EditTextPreference onclick

时间:2012-06-19 09:54:51

标签: android onclick preferences

我正在进行设置活动,我想让用户选择声音通知。我用这个来做:

EditTextPreference dataPref = (EditTextPreference) findPreference("opcion3");

        dataPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            public boolean onPreferenceClick(Preference preference) {
                Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
                Ajustes.this.startActivityForResult(intent, 5);          
                return true;
            }
          });  

但是当我点击EditTextPreference时,它会显示一个带有OK和取消的编辑框,并且它会立即显示通知声音列表。

我怎样才能让它只显示通知声音?

1 个答案:

答案 0 :(得分:1)

为什么使用EditTextPreference? 使用RingtonePreference或创建自定义首选项。

<RingtonePreference 
    android:key="notification_sound" 
    android:ringtoneType="notification" 
    android:title="Notification Sound" 
    android:defaultValue="content://settings/system/notification_sound"
    android:showDefault="true" 
    android:showSilent="true" />