我有一个DialogFragment
弹出自定义铃声选择器。Ringtone
但是,在选择一个并单击“确定”后,它不会正确。知道下面有什么问题吗?
对话框由此创建
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
rm = new RingtoneManager(getActivity());
ringtones = rm.getCursor();
int selected = -1;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.ringtone);
builder.setSingleChoiceItems(ringtones,
selected,
ringtones.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX),
mChoiceListener);
builder.setPositiveButton("OK", this);
builder.setNegativeButton("Cancel", this);
return builder.create();
}
private DialogInterface.OnClickListener mChoiceListener =
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int position) {
ringtones.moveToPosition(position);
}
};
当 OK 按钮被选中时,它被捕获
public void onClick(DialogInterface dialog, int which) {
Log.d("DayPickerFragment", "onClick");
switch(which) {
case Dialog.BUTTON_NEGATIVE:
dialog.cancel();
break;
case Dialog.BUTTON_POSITIVE:
Uri uri = rm.getRingtoneUri(ringtones.getPosition());
Ringtone r = RingtoneManager.getRingtone(getActivity(), uri);
/*** etc ***/
/*** returned ringtone doesn't match what was selected ***/
dialog.dismiss();
break;
}
}
是不是铃声光标rm.getRingtoneUri(position)
对应的方法不对?如果是这样,您如何获得所选项目的真实性?Uri
任何帮助表示赞赏。