导航到其他视图时如何解决活动未找到异常?

时间:2019-06-02 14:39:57

标签: xamarin.android

当我想转到另一个活动时,我得到了一个Android.Content.ActivityNotFoundException: 另外,每次我想查看我的应用程序时,都必须重新创建模拟器,因为它会在我第二次启动模拟器时始终导致adb错误。

我读到这可能是由另一个异常引起的,但是我检查了另一个代码,却没有找到任何东西

Button btnentrar = FindViewById<Button>(Resource.Id.createlist);

        btnentrar.Click += delegate
        {
            StartActivity(typeof(listeditorclass));
        };

//活动:

    private List<string> mItems;
    private ListView mListView;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.listeditor);
        mListView = FindViewById<ListView>(Resource.Id.listView);

        mItems = new List<string>();
        mItems.Add("Milch");
        mItems.Add("Brot");
        mItems.Add("Apfel");

        MyListViewAdapter adapter = new MyListViewAdapter(this, mItems);

        mListView.Adapter = adapter;}

我也不知道AppCompatActivity和正常活动之间的区别。因此,一般来说,当用户单击按钮时,应该会看到带有我的列表的新视图(创建列表)。

1 个答案:

答案 0 :(得分:0)

我以前没有在Xamarin上使用匿名委托,这很酷。尝试使用意图并传递Context

    btnentrar.Click += delegate
    {
        StartActivity(new Intent(this, typeof(listeditorclass)));
    };