c#,Xamarinともに初心者になります。
よろしくお願いします。
マイクロソフトのチュートリアル
"Hello Android のマルチスクリーン"に沿って学習しております
https://docs.microsoft.com/ja-jp/xamarin/android/get-started/hello-android-multiscreen/hello-android-multiscreen-quickstart?pivots=windows
環境:
windows10 64bit
Microsoft Visual Studio Community 2019
Version 16.5.4
行いたいことは
以下のコンパイルエラーを解決したいことです。
エラー CS0246
型または名前空間の名前 'TranslationHistoryActivity' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
該当の処理は以下になります。
c#
1var intent = new Intent(this, typeof(TranslationHistoryActivity));
下の方にソースはまとめて記載しておりますが、その内
MainActivity.csの中から
TranslationHistoryActivity.csに定義されているクラス名TranslationHistoryActivity
を使用して、以下のコードにて画面遷移させようとしているのですが
上記のエラーコードにてコンパイルエラーとなります
クラス名TranslationHistoryActivityを解決するためには
AndroidManifest.xmlに該当のアクティビティが登録されている必要があると思っていますが
以下ソースの通り追加がありませんでした。これがエラーの原因だと思っておりますが、どのような操作を行えば追加されますでしょうか。(アクティビティを追加した時点で自動に追加されるものかと思っております)
MainActivity.cs
c#
1using System.Collections.Generic; 2using Android.Content; 3using Android.App; 4using Android.OS; 5using Android.Support.V7.App; 6using Android.Runtime; 7using Android.Widget; 8 9namespace phoneword 10{ 11 // Activity属性 12 [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)] 13 //[Activity(Label = "Phoneword", MainLauncher = true)] 14 public class MainActivity : AppCompatActivity 15 { 16 static readonly List<string> phoneNumbers = new List<string>();//電話番号を入力できる空のリスト 17 18 protected override void OnCreate(Bundle savedInstanceState) 19 { 20 base.OnCreate(savedInstanceState); 21 // Set our view from the "main" layout resource 22 //ユーザー インターフェイスの読み込み 23 SetContentView(Resource.Layout.activity_main); 24 25 // New code will go here 26 27 // Get our UI controls from the loaded layout 28 // コントロールのリソース ID の取得 29 EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText); 30 TextView translatedPhoneWord = FindViewById<TextView>(Resource.Id.TranslatedPhoneword); 31 Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton); 32 Button translationHistoryButton = FindViewById<Button>(Resource.Id.TranslationHistoryButton); 33 34 // Add code to translate number ★ソースの見方がよくわからない。。。デバックしてみる 35 string translatedNumber = string.Empty; 36 translateButton.Click += (sender, e) => 37 { 38 // Translate user's alphanumeric phone number to numeric 39 translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text); 40 if (string.IsNullOrWhiteSpace(translatedNumber)) 41 { 42 translatedPhoneWord.Text = ""; 43 } 44 else 45 { 46 translatedPhoneWord.Text = translatedNumber; 47 phoneNumbers.Add(translatedNumber); 48 translationHistoryButton.Enabled = true; 49 } 50 }; 51 52 translationHistoryButton.Click += (sender, e) => 53 { 54 //var intent = new Intent(this, typeof(TranslationHistoryActivity));//★ここでエラーがでる 55 var intent = new Intent(this, typeof(TranslationHistoryActivity)); 56 intent.PutStringArrayListExtra("phone_numbers", phoneNumbers); 57 StartActivity(intent); 58 }; 59 60 } 61 public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults) 62 { 63 Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); 64 65 base.OnRequestPermissionsResult(requestCode, permissions, grantResults); 66 } 67 } 68}
TranslationHistoryActivity.cs
C#
1using System; 2using System.Collections.Generic; 3using Android.App; 4using Android.OS; 5using Android.Widget; 6namespace Phoneword 7{ 8 [Activity(Label = "@string/translationHistory")] 9 public class TranslationHistoryActivity : ListActivity 10 { 11 protected override void OnCreate(Bundle bundle) 12 { 13 base.OnCreate(bundle); 14 // Create your application here 15 var phoneNumbers = Intent.Extras.GetStringArrayList("phone_numbers") ?? new string[0]; 16 this.ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, phoneNumbers); 17 18 } 19 } 20}
AndroidManifest.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 android:versionCode="1" 4 android:versionName="1.0" 5 package="com.companyname.phoneword"> 6 <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" /> 7 <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> 8 </application> 9 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 10</manifest>
以上です。ご確認の程、よろしくお願い致します
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/28 03:11