2014-11-16 46 views
3

設備上顯示我剛發現我的一箇舊應用程序出現對話框問題。它正在使用actionbarsherlock。在應用程序中,某些對話框不顯示在android v4 +上。我想更新應用程序,但我無法將應用程序遷移到AppCompat,因爲它會花費太多的工作量。Sherlock對話框片段不能在Android v4 +

我顯示一個對話框時,點擊列表項

@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(); 
    } 

} 

只有編碼器和格式dialongs沒有顯示然而其他人工作的罰款。 這是怎麼了顯示對話框

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"); 
} 

這些都是我的對話片段類

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

回答

0

在你的AudioEncoderDialog.onCreateDialog之內,你很清楚沒有處理KitKat的情況,是您正在測試的設備。