gpt4 book ai didi

android - Sherlock 对话框 fragment 未在 Android v4+ 设备上显示

转载 作者:太空狗 更新时间:2023-10-29 15:00:51 25 4
gpt4 key购买 nike

我刚刚发现我的一个旧应用程序存在对话框问题。它正在使用 actionbarsherlock。在应用程序中,某些对话框不会在 android v4+ 上显示。我想更新应用程序,但无法将应用程序迁移到 AppCompat,因为这会带来很多工作。

我在单击列表项时显示一个对话框

    @Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String selected = titles[position];

if (selected.equals(first)) {
showAudioSourceDialog();
} else if (selected.equals(second)) {
showAudioEncoderDialog();
} else if (selected.equals(third)) {
showSamplingRateDialog();
} else if (selected.equals(fourth)) {
showAudioBitrateDialog();
} else if (selected.equals(fifth)) {
showAudioFormatDialog();
} else if (selected.equals(sixth)) {
showAudioChannelDialog();
} else if (selected.equals(seventh)) {
showAudioBackgroundRecordingDialog();
}

}

只有编码器和格式拨号没有显示,但其他的工作正常。这就是我显示对话框的方式

 private void showAudioFormatDialog() {
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment prev = getFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);

// Create and show the dialog.
DialogFragment newFragment = AudioFormatDialog.newInstance();

newFragment.show(ft, "dialog");
}

private void showAudioBitrateDialog() {
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment prev = getFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);

// Create and show the dialog.
DialogFragment newFragment = AudioBitrateDialog.newInstance();

newFragment.show(ft, "dialog");
}
private void showAudioEncoderDialog() {
// DialogFragment.show() will take care of adding the fragment
// in a transaction. We also want to remove any currently showing
// dialog, so make our own transaction and take care of that here.
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment prev = getFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);

// Create and show the dialog.
DialogFragment newFragment = AudioEncoderDialog.newInstance();

newFragment.show(ft, "dialog");
}

这些是我的对话框 fragment 类

public static class AudioEncoderDialog extends SherlockDialogFragment {

public static AudioEncoderDialog newInstance() {
AudioEncoderDialog frag = new AudioEncoderDialog();
return frag;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog levelDialog;
CharSequence[] items = null;
int option = getAudioEncoderOption();
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.FROYO) {

items = new CharSequence[] { "AMR_NB(Narrowband)" };
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1) {

items = new CharSequence[] { " AMR (Narrowband)",
" AMR (Wideband)", "AAC Low Complexity (AAC-LC)" };
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {

items = new CharSequence[] { " AMR_NB(Narrowband)",
" AMR (Wideband)", "AAC Low Complexity (AAC-LC)",
"Enhanced Low Delay AAC (AAC-ELD)",
"High Efficiency AAC (HE-AAC)" };

}
// Creating and Building the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Choose your Audio Encoder");
levelDialog = builder.create();
builder.setSingleChoiceItems(items, option,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {

switch (item) {
case 0:

break;
case 1:

break;
case 2:

break;
case 3:


break;
case 4:

break;

}
levelDialog.dismiss();
}
});

return builder.create();

}

}

public static class AudioBitrateDialog extends SherlockDialogFragment {

public static AudioBitrateDialog newInstance() {
AudioBitrateDialog frag = new AudioBitrateDialog();
return frag;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog levelDialog;
int option = getAudioBitrateOption();
// Strings to Show In Dialog with Radio Buttons
final CharSequence[] items = { " 8Bit ", " 16Bit" };

// Creating and Building the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Choose your Audio Bitrate");
levelDialog = builder.create();
builder.setSingleChoiceItems(items, option,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {

switch (item) {
case 0:

dismiss();

break;
case 1:

break;

}
levelDialog.dismiss();
}
});

return builder.create();

}
}

显示了音频比特率对话框,但未显示编码器对话框,两者似乎具有几乎相同的代码。我怎样才能让所有的对话框都显示出来?

这就是我希望它在每台设备上的显示方式:

enter image description here

这是它在我的 nexus 5 和带有 android 4.4 的模拟器上的显示方式:

enter image description here

最佳答案

在您的 AudioEncoderDialog.onCreateDialog 中,您很明显没有处理 KitKat 的情况,这是您正在测试的设备。

关于android - Sherlock 对话框 fragment 未在 Android v4+ 设备上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26960752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com