SherlockDialogFragment onCreateView需要创建的活动

时间:2014-08-03 18:02:24

标签: android-activity android-dialogfragment

如何处理自定义SherlockDialogFragment onCreateView()需要活动来构建其视图的情况?
更具体地说,需要在构建视图之前执行onCreate()方法的活动。自定义SherlockDialogFragment是EffectSettingsDialog 我总是可以在模拟器中重现异常(我在评论部分提到)(用api级别10测试)。
如果按ctrl-f11(或ctrl-f12)显示对话框,应用程序崩溃 该应用程序被认为是在横向模式下工作(所以我设置了android:screenOrientation =" landscape"在应用程序清单中)。

EffectSettingsDialog.java

/**
 * 
 * @author
 *
 */
public class EffectSettingsDialog extends SherlockDialogFragment
{
    final   static  String  DIALOG_TAG = "effect_settings_dialog";


    final           int     UNKNOWN_BUTTON = 0;
    final           int     OK_BUTTON = 1;
    final           int     CANCEL_BUTTON = 2;
    final           int     RESET_BUTTON = 3;
    int             pressed_button = UNKNOWN_BUTTON;


    /**
     * 
     */
    public EffectSettingsDialog( )
    {
        super();

        CLog.i( "EffectSettingsDialog", "EffectSettingsDialog()" );
    }




     /**
     * Create a new instance of WelcomeDialog.
     */
    static EffectSettingsDialog newInstance()
    {
        EffectSettingsDialog d = new EffectSettingsDialog();

        return d;
    }   


    /**
     * 
     */
    static  boolean showNewInstance( FragmentActivity   activity, int   fx_id )
    {       
        if ( fx_id == -1 )
            return  false;

        Fragment prev = activity.getSupportFragmentManager().findFragmentByTag( EffectSettingsDialog.DIALOG_TAG );      
        if (prev != null)
            return  false;
        EffectSettingsDialog    d = EffectSettingsDialog.newInstance();

        // Supply fx_id parameter to the fragment
        Bundle args = new Bundle();
        args.putInt( "fx_id", fx_id );
        d.setArguments(args);

        d.show( activity.getSupportFragmentManager(), EffectSettingsDialog.DIALOG_TAG );        
        return  true;
    }






    @Override
    public void onCreate( Bundle savedInstanceState ) 
    {
        CLog.i( "EffectSettingsDialog", "onCreate()" );
        super.onCreate(savedInstanceState);
        int style = SherlockDialogFragment.STYLE_NO_TITLE;     
        int theme = getTheme();
        setStyle(style, theme );//, theme);
    }


    @Override
    public Dialog onCreateDialog(Bundle savedInstanceStateBundle ) 
    {
        CLog.i( "EffectSettingsDialog", "onCreateDialog()" );
        // TODO Auto-generated method stub
        Dialog  d = super.onCreateDialog( savedInstanceStateBundle );       
        return  d;  
    }


    @Override
    public  View    onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState )
    {   
        CLog.i( "EffectSettingsDialog", "onCreateView()" );

        /// Here i need to call  ((MyActivity)getActivity()).getData() to properly initialize the view. Initialization code omitted...


        getDialog().getWindow().setBackgroundDrawableResource( R.color.transparent );//translucent_black );
        getDialog().getWindow().clearFlags( WindowManager.LayoutParams.FLAG_DIM_BEHIND );

        return v;
    }

}

在活动中(在onClick()方法中),我使用以下代码:

EffectSettingsDialog.showNewInstance( this, fx_id );

当用户触摸特定按钮时会发生这种情况。

0 个答案:

没有答案