xamarin android AddToBackStack(typeof(MainActivity).Name)不起作用

时间:2018-01-02 08:04:16

标签: c# android xamarin

请帮我解决这个问题 亲爱的朋友们,您好。 我正在开发一款应用。我不知道为什么命令无法恢复到应用程序中的上一个屏幕。 按后退按钮退出应用程序。 该应用正在向fragment manager Backstack运行添加的数据。

namespace SakhtemanYar
{
    public class MainFragment : Fragment, Com.Mohamadamin.Persianmaterialdatetimepicker.Date.DatePickerDialog.IOnDateSetListener
    {
        // Global variables

    public MainFragment(Context context, int pageid, Account myaccount, ConnectivityManager conn, List<Setting> appstgs, object transaction = null, string objecttype = "")
    {
        PageID = pageid;
        // main startup operations
        string path = "BKoodkBd.ttf";
        FontTypeface = Typeface.CreateFromAsset(context.Assets, path);

    }
    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view;

        if (PageID == 0)
        {
            view = inflater.Inflate(Resource.Layout.HomePage, container, false);
    ...
    ...
            SeewIV.Click += delegate
            {
                SetLayoutPage(15, true);
            };
        }

        else
            view = inflater.Inflate(Resource.Layout.HomePage, container, false);
        return view;
    }

    public void SetLayoutPage(int pageid, bool rollback = false, object transobject = null, string objecttype = "")
    {
        if (transobject == null && objecttype == "")
        {
            var newFragment = new MainFragment(Context, pageid, MyAccountFr, connectivityManager, AppSettings);
            var ft = FragmentManager.BeginTransaction();
            ft.Replace(Resource.Id.MainFrame, newFragment);

            if (rollback)
                ft.AddToBackStack(typeof(MainActivity).Name);

            ft.Commit();
        }
        else
        {
            var newFragment = new MainFragment(Context, pageid, MyAccountFr, connectivityManager, AppSettings, transobject, objecttype);
            var ft = FragmentManager.BeginTransaction();
            ft.Replace(Resource.Id.MainFrame, newFragment);

            if (rollback)
                ft.AddToBackStack(typeof(MainActivity).Name);

            ft.Commit();
        }
    }
}}

1 个答案:

答案 0 :(得分:0)

公共类MainFragment:Fragment

=&gt;

public class MainFragment:Android.Support.V4.App.Fragment