C# “沙马林”;名称空间,但与类型“类似”;错误
我在看一段视频,教我们如何使用Xamarin Studio开发应用程序。我跟那家伙一模一样。但现在我发现了错误 “ListView是一个“命名空间”,但与类型一样使用” 这是我的密码C# “沙马林”;名称空间,但与类型“类似”;错误,c#,android,C#,Android,我在看一段视频,教我们如何使用Xamarin Studio开发应用程序。我跟那家伙一模一样。但现在我发现了错误 “ListView是一个“命名空间”,但与类型一样使用” 这是我的密码 int count = 1; private List<string> mItem; private ListView mListView; protected override void OnCreate (Bundle bundle) { base.
int count = 1;
private List<string> mItem;
private ListView mListView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
mListView = FindViewById<ListView> (Resource.Id.mylistview);
mItem = new List<string> ();
//Add Items
mItem.Add ("Tom");
mItem.Add ("Bob");
mItem.Add ("Jack");
ArrayAdapter<string> adapter = new ArrayAdapter<string> (this, Android.Resource.Layout.SimpleListItem1, mItem);
mListView.Adapter = adapter;
}
int count=1;
私有列表;
私有列表视图;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
mListView=findviewbyd(Resource.Id.mylistview);
mItem=新列表();
//添加项目
加上(“汤姆”);
加上(“Bob”);
加上“千斤顶”;
ArrayAdapter=新的ArrayAdapter(this,Android.Resource.Layout.SimpleListItem1,mItem);
mListView.Adapter=适配器;
}
因为您将项目命名为ListView,所以每当您在代码中使用ListView
时,它会认为您引用的是名称空间,因为这是项目的名称。那么就不能再将ListView用作类型了
选择一个不同的项目名称,它应该可以工作。请记住,永远不要在关键字或类型名称后命名项目。它不应该是名称空间。。。您没有将项目命名为“ListView”?我将项目命名为ListView对不起,先生,我不太明白您所说的“它不应该是名称空间”是什么意思。我想我找到了解决方案,如果我将项目命名为不同的名称,那么“ListView”就可以了,因为您将项目命名为ListView,它的默认名称空间也将是ListView。这就是为什么会有一个名称空间,否则就没有了。对不起,我不知道,我会知道的。谢谢你的提醒