使用框架对话框在我的片段中不起作用:getActivity()

时间:2014-09-02 02:18:29

标签: android android-fragments android-dialog

我想在我的片段中使用github" android-times-square"模型对话框,但上下文不起作用。

当我点击我的客户视图而不是

时,我使用Debug模型

错误" android.view.InflateException:二进制XML文件行#1:错误导致类com.squareup.timessquare.CalendarPickerView"

我的错误在别的地方吗?谢谢。

myActivity

public class MyActivity extends Activity {
....
                 getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment())
                .commit();
}

myFragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    final Calendar nextYear = Calendar.getInstance();
    nextYear.add(Calendar.YEAR, 1);

    final Calendar lastYear = Calendar.getInstance();
    lastYear.add(Calendar.YEAR, -1);

    final View  rootView = inflater.inflate(R.layout.my_click_view, container, false);
       rootView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {

                dialogView = (CalendarPickerView)getActivity().getLayoutInflater().inflate(R.layout.dialog, null, false);
                dialogView.init(lastYear.getTime(), nextYear.getTime()) //
                        .withSelectedDate(new Date());
                theDialog =
                        new AlertDialog.Builder(rootView.getContext()).setTitle("I'm a dialog!")
                                .setView(dialogView)
                                .setNeutralButton("Dismiss", new DialogInterface.OnClickListener() {
                                    @Override public void onClick(DialogInterface dialogInterface, int i) {
                                        dialogInterface.dismiss();
                                    }
                                })
                                .create();
                theDialog.setOnShowListener(new DialogInterface.OnShowListener() {
                    @Override
                    public void onShow(DialogInterface dialogInterface) {
                        Log.d(TAG, "onShow: fix the dimens!");
                        dialogView.fixDialogDimens();
                    }
                });
                theDialog.show();
            }
            return true;
        }
    });
    return rootView;
}

0 个答案:

没有答案