片段管理器错误:非静态字段,方法或属性需要对象引用

时间:2015-04-25 19:19:42

标签: c# android xamarin

我收到此错误:对于非静态字段,方法或属性'Android.App.FragmentManager.BeginTransaction()'在行中需要对象引用:FragmentTransaction transaction = FragmentManager.BeginTransaction();

void mEditar_Click (object sender, EventArgs e )
            {
                FragmentTransaction transaction = FragmentManager.BeginTransaction();

                dialog_Editar_produto dialog_editar = new dialog_Editar_produto ();
                dialog_editar.Show (transaction, "dialog fragment");

                dialog_editar.mOnEditarComplete += dialog_editar_mOnEditarComplete;

            }

我该怎么办?

2 个答案:

答案 0 :(得分:0)

该错误消息表明BeginTransaction不是FragmentManager类的静态方法。 尝试访问班级中的FragmentManager对象。

试试这个:

FragmentTransaction transaction = this.FragmentManager.BeginTransaction();

答案 1 :(得分:0)

使用此代码:

FragmentManager fragmentManager = getFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

了解更多信息 http://developer.android.com/guide/components/fragments.html