你们能帮我提供我的代码吗?
list_bt = FindViewById(Resource.Id.list_view);
它说“'Resource.Id'不包含“ list_view”的定义””但我已经在.xml文件中声明了ListView ID为list_view。以下是我的.cs文件
Android.App;
using Android.Bluetooth;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Widget;
namespace Test1
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
CheckBox enableBt, enableVisible;
TextView nameBt;
Button search_button;
ListView list_bt;
private BluetoothAdapter BA;
private JavaSet<BluetoothDevice> pairedDevices;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
enableBt = (CheckBox)FindViewById(Resource.Id.enableBt);
enableVisible = (CheckBox)FindViewById(Resource.Id.enableVisible);
nameBt = (TextView)FindViewById(Resource.Id.text1);
search_button = (Button)FindViewById(Resource.Id.search_button);
list_bt = FindViewById(Resource.Id.list_view);
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
最近我遇到了同样的问题。 Visual Studio环境可能正在运行,因此您可以删除Resource.designer.cs
中的所有代码并重新编译。另外,您可以清除.xml文件的编译文件,然后返回所有代码并再次编译。顺便说一下,nameBt = (TextView)FindViewById(Resource.Id.text1);
看起来更好,因为nameBt = FindViewById<TextView>(Resource.Id.text1);