using Android.App;
using Android.Widget;
using Android.OS;
using Android.Media;
namespace Moosic
{
[Activity(Label = "Moosic", MainLauncher = true, Icon = "@drawable/icon1.png")]
public class MainActivity : Activity
{
MediaPlayer player;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
player = MediaPlayer.Create(this, Resource.Raw.again);
Button button1 = FindViewById<Button>(Resource.Id.playButton);
button1.Click += (sender, e) =>
{
player.Start();
};
}
}
}
错误CS0117&#39; Resource.Id&#39;不包含&#39; playButton&#39;的定义Moosic c:\ users \ Farorex \ source \ repos \ Moosic \ Moosic \ MainActivity.cs 25 Active
创建一个简单的媒体播放器,尝试重建解决方案并清理解决方案,但似乎无法正常工作
答案 0 :(得分:0)
你如何设置该按钮的ID? 我见过人们犯的常见错误是使用 @id 而不是 @ + id
在您的活动布局中,您应该:
<Button
android:id="@+id/playButton"
...
/>
否则,它将不会在Resource.designer.cs中创建