我试图给家庭片段类充气并且我收到了这个错误:
类型或命名空间名称' DashboardFragment'找不到(你错过了使用指令或汇编引用吗?)
这是我的主要活动类:
Subject
这是我的片段类:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.Design.Widget;
using SupportFragment = Android.Support.V4.App.Fragment;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using Android.Views;
namespace LottoGenie.Androidv2
{
[Activity(Label = "LottoGenie.Androidv2", MainLauncher = true, Icon ="@drawable/ic_launcher")]
public class MainActivity : Activity
{
private DrawerLayout drawerLayout;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
var toolbar = FindViewById<Toolbar>(Resource.Id.app_bar);
SetActionBar(toolbar);
ActionBar.SetTitle(Resource.String.ApplicationName);
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetDisplayShowHomeEnabled(true);
var navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;
var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, Resource.String.open_drawer, Resource.String.close_drawer);
drawerLayout.AddDrawerListener(drawerToggle);
drawerToggle.SyncState();
var ft = this.FragmentManager.BeginTransaction();
ft.AddToBackStack(null);
ft.Add(Resource.Id.HomeFrameLayout, new DashboardFragment());
ft.Commit();
}
protected override void OnResume()
{
ActionBar.SetTitle(Resource.String.ApplicationName);
base.OnResume();
}
void NavigationView_NavigationItemSelected(object sender, NavigationView.NavigationItemSelectedEventArgs e)
{
switch (e.MenuItem.ItemId)
{
case (Resource.Id.nav_home):
Toast.MakeText(this, "Home!", ToastLength.Short).Show();
break;
case (Resource.Id.nav_powerball):
Toast.MakeText(this, "Powerball Picks!", ToastLength.Short).Show();
break;
case (Resource.Id.nav_megamillions):
Toast.MakeText(this, "MegaMillions Picks!", ToastLength.Short).Show();
break;
case (Resource.Id.nav_jumbobucks):
Toast.MakeText(this, "Jumbobucks Picks!", ToastLength.Short).Show();
break;
}
drawerLayout.CloseDrawers();
}
public override bool OnCreateOptionsMenu(Android.Views.IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.action_menu, menu);
if (menu != null)
{
menu.FindItem(Resource.Id.action_refresh).SetVisible(true);
}
return base.OnCreateOptionsMenu(menu);
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Android.Resource.Id.Home:
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
public override void OnBackPressed()
{
if (FragmentManager.BackStackEntryCount != 0)
{
FragmentManager.PopBackStack();
}
else
{
base.OnBackPressed();
}
}
}
}
我错过了什么?提前谢谢。
答案 0 :(得分:0)
我找到了一个解决方法。事实证明,我有新的字符串和视图没有更新到资源设计器文件。我必须先将这些行添加到.csproj文件中的第一个PropertyGroup中:
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<AndroidResgenClass>Resource</AndroidResgenClass>
之后我执行了清理和重建。然后我删除了上面的行并运行了另一个构建。修好了!感谢