gpt4 book ai didi

c# - CS0117 C# 'Resource.Id' 不包含 "PhoneNumberText"的定义

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:35:11 25 4
gpt4 key购买 nike

我将 Visual Studio 2015 与 Xamarin 结合使用。我将我的项目命名为“Phoneword”我在 Xamarin 的网站上看到了这段代码,例如教程/示例。

TranslateButtonCallButton 成员出现同样的错误。

MainActivity.cs

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Phoneword
{
[Activity(Label = "Phoneword", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);

// Our code will go here
// Get our UI controls from the loaded layout:
EditText phoneNumberText = (EditText)FindViewById(Resource.Id.PhoneNumberText);
Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
Button callButton = FindViewById<Button>(Resource.Id.CallButton);

// Disable the "Call" button
callButton.Enabled = false;

// Add code to translate number
string translatedNumber = string.Empty;

translateButton.Click += (object sender, EventArgs e) =>
{
// Translate user's alphanumeric phone number to numeric
translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text);
if (String.IsNullOrWhiteSpace(translatedNumber))
{
callButton.Text = "Call";
callButton.Enabled = false;
}
else
{
callButton.Text = "Call " + translatedNumber;
callButton.Enabled = true;
}
};

callButton.Click += (object sender, EventArgs e) =>
{
// On "Call" button click, try to dial phone number.
var callDialog = new AlertDialog.Builder(this);
callDialog.SetMessage("Call " + translatedNumber + "?");
callDialog.SetNeutralButton("Call", delegate {
// Create intent to dial phone
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
StartActivity(callIntent);
});
callDialog.SetNegativeButton("Cancel", delegate { });

// Show the alert dialog to the user and wait for response.
callDialog.Show();
};
}

}
}

Resource/Layout/Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Enter a Phoneword"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PhoneNumberText"
android:text="1-855-XAMARIN" />
<Button
android:text="Translate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TranslateButton" />
<Button
android:text="Call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CallButton" />
</LinearLayout>

我是 Android 开发的初学者,如果您需要其他信息,我会尝试添加更多详细信息。请帮助我

最佳答案

我的问题解决了!从 Tools/Android SDK Manager 我卸载了:

  • Android SDK 构建工具 24
  • 安卓 N(API 24)

我安装了:

  • Android 6.0 (API 23)
  • Android SDK 构建工具 23.0.3
  • Android SDK 构建工具 23.0.2

关闭 VS 并重新启动它后...在解决方案资源管理器中,我选择了“清理解决方案”,然后选择了“重建解决方案”。

关于c# - CS0117 C# 'Resource.Id' 不包含 "PhoneNumberText"的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38103271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com