質問するログイン新規登録

質問編集履歴

6

こーど

2017/12/24 17:49

投稿

mercurian-teto
mercurian-teto

スコア75

title CHANGED
File without changes
body CHANGED
@@ -283,4 +283,9 @@
283
283
  }
284
284
  #pragma warning restore 1591
285
285
 
286
- ```
286
+ ```
287
+ ```C#
288
+ Button btnM = FindViewById<Button>(Resource.Id.btnSayHello);
289
+ TextView txtV = FindViewById<TextView>(Resource.Id.txtMsg);
290
+ ```
291
+ にたいして ResouceにIDの定義がありませんと出てきます

5

こーど

2017/12/24 17:49

投稿

mercurian-teto
mercurian-teto

スコア75

title CHANGED
File without changes
body CHANGED
@@ -146,4 +146,141 @@
146
146
  Button btnM = FindViewById<Button>(Resource.Id.btnSayHello);
147
147
  TextView txtV = FindViewById<TextView>(Resource.Id.txtMsg);
148
148
  ```
149
- これらのコードに対して現在のコンテキストにresourceという名前は存在しません
149
+ これらのコードに対して現在のコンテキストにresourceという名前は存在しません
150
+
151
+ 追記4再度作り直しました
152
+
153
+ MainActivity.cs
154
+ ```
155
+ using Android.App;
156
+ using Android.Widget;
157
+ using Android.OS;
158
+
159
+ namespace App5
160
+ {
161
+ [Activity(Label = "DroidSample", MainLauncher = true, Icon = "@drawable/icon")]
162
+ public class MainActivity : Activity
163
+ {
164
+
165
+ protected override void OnCreate(Bundle bundle)
166
+ {
167
+ base.OnCreate(bundle);
168
+
169
+ // Set our view from the "main" layout resource
170
+ SetContentView(Resource.Layout.Main);
171
+
172
+ Button btnM = FindViewById<Button>(Resource.Id.btnSayHello);
173
+ TextView txtV = FindViewById<TextView>(Resource.Id.txtMsg);
174
+
175
+ btnM.Click += delegate
176
+ {
177
+ txtV.Text = "こんにちは";
178
+ };
179
+ }
180
+ }
181
+ }
182
+
183
+ ```
184
+ Main.axml
185
+ ```C#
186
+ <?xml version="1.0" encoding="utf-8"?>
187
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
188
+ android:orientation="vertical"
189
+ android:layout_width="match_parent"
190
+ android:layout_height="match_parent">
191
+ <Button
192
+ android:text="Button"
193
+ android:layout_width="match_parent"
194
+ android:layout_height="wrap_content"
195
+ android:id="@+id/btnSayHello" />
196
+ <TextView
197
+ android:text="Large Text"
198
+ android:textAppearance="?android:attr/textAppearanceLarge"
199
+ android:layout_width="match_parent"
200
+ android:layout_height="wrap_content"
201
+ android:id="@+id/txtMsg" />
202
+ </LinearLayout>
203
+ ```
204
+ Resource.Designer.cs
205
+
206
+ も追記しておきました
207
+ ```C#
208
+ #pragma warning disable 1591
209
+ //------------------------------------------------------------------------------
210
+ // <auto-generated>
211
+ // このコードはツールによって生成されました。
212
+ // ランタイム バージョン:4.0.30319.42000
213
+ //
214
+ // このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
215
+ // コードが再生成されるときに損失したりします。
216
+ // </auto-generated>
217
+ //------------------------------------------------------------------------------
218
+
219
+ [assembly: global::Android.Runtime.ResourceDesignerAttribute("App5.Resource", IsApplication=true)]
220
+
221
+ namespace App5
222
+ {
223
+
224
+
225
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
226
+ public partial class Resource
227
+ {
228
+
229
+ static Resource()
230
+ {
231
+ global::Android.Runtime.ResourceIdManager.UpdateIdValues();
232
+ }
233
+
234
+ public static void UpdateIdValues()
235
+ {
236
+ }
237
+
238
+ public partial class Attribute
239
+ {
240
+
241
+ static Attribute()
242
+ {
243
+ global::Android.Runtime.ResourceIdManager.UpdateIdValues();
244
+ }
245
+
246
+ private Attribute()
247
+ {
248
+ }
249
+ }
250
+
251
+ public partial class Layout
252
+ {
253
+
254
+ // aapt resource value: 0x7f020000
255
+ public const int Main = 2130837504;
256
+
257
+ static Layout()
258
+ {
259
+ global::Android.Runtime.ResourceIdManager.UpdateIdValues();
260
+ }
261
+
262
+ private Layout()
263
+ {
264
+ }
265
+ }
266
+
267
+ public partial class String
268
+ {
269
+
270
+ // aapt resource value: 0x7f030000
271
+ public const int app_name = 2130903040;
272
+
273
+ static String()
274
+ {
275
+ global::Android.Runtime.ResourceIdManager.UpdateIdValues();
276
+ }
277
+
278
+ private String()
279
+ {
280
+ }
281
+ }
282
+ }
283
+ }
284
+ #pragma warning restore 1591
285
+
286
+ ```

4

コード付け足し

2017/12/24 17:46

投稿

mercurian-teto
mercurian-teto

スコア75

title CHANGED
File without changes
body CHANGED
@@ -81,4 +81,69 @@
81
81
  android:layout_height="wrap_content"
82
82
  android:id="@+id/textMsg" />
83
83
  </LinearLayout>
84
- ```
84
+ ```
85
+
86
+ 追記3
87
+
88
+ 上のプログラムがなぜか起動できなくなったので再度作り直しました。
89
+ コードは以下に示します。
90
+ Main.axml
91
+ ```C#
92
+ <?xml version="1.0" encoding="utf-8"?>
93
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
94
+ android:orientation="vertical"
95
+ android:layout_width="match_parent"
96
+ android:layout_height="match_parent">
97
+ <Button
98
+ android:text="Button"
99
+ android:layout_width="match_parent"
100
+ android:layout_height="wrap_content"
101
+ android:id="@+id/btnSayHello" />
102
+ <TextView
103
+ android:text="Large Text"
104
+ android:textAppearance="?android:attr/textAppearanceLarge"
105
+ android:layout_width="match_parent"
106
+ android:layout_height="wrap_content"
107
+ android:id="@+id/txtMsg" />
108
+ </LinearLayout>
109
+ ```
110
+
111
+ MainActivity.cs
112
+ ```C#
113
+ using Android.App;
114
+ using Android.Widget;
115
+ using Android.OS;
116
+
117
+ namespace anti_offtime
118
+ {
119
+ [Activity(Label = "offtimekiller", MainLauncher = true, Icon = "@drawable/icon")]
120
+ public class MainActivity : Activity
121
+ {
122
+
123
+ protected override void OnCreate(Bundle bundle)
124
+ {
125
+ base.OnCreate(bundle);
126
+
127
+ // Set our view from the "main" layout resource
128
+ SetContentView(Resource.Layout.Main);
129
+
130
+ Button btnM = FindViewById<Button>(Resource.Id.btnSayHello);
131
+ TextView txtV = FindViewById<TextView>(Resource.Id.txtMsg);
132
+
133
+ btnM.Click += delegate
134
+ {
135
+ txtV.Text = "こんにちは";
136
+ };
137
+ }
138
+ }
139
+ }
140
+ ```
141
+ エラーが
142
+ ```C#
143
+ // Set our view from the "main" layout resource
144
+ SetContentView(Resource.Layout.Main);
145
+
146
+ Button btnM = FindViewById<Button>(Resource.Id.btnSayHello);
147
+ TextView txtV = FindViewById<TextView>(Resource.Id.txtMsg);
148
+ ```
149
+ これらのコードに対して現在のコンテキストにresourceという名前は存在しません

3

code 追加

2017/12/24 15:08

投稿

mercurian-teto
mercurian-teto

スコア75

title CHANGED
File without changes
body CHANGED
@@ -57,6 +57,7 @@
57
57
  }
58
58
  ```
59
59
  追記2
60
+ Main.axml
60
61
  ```C#
61
62
  <?xml version="1.0" encoding="utf-8"?>
62
63
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

2

コード追加

2017/12/24 12:23

投稿

mercurian-teto
mercurian-teto

スコア75

title CHANGED
File without changes
body CHANGED
@@ -55,4 +55,29 @@
55
55
  }
56
56
  }
57
57
  }
58
+ ```
59
+ 追記2
60
+ ```C#
61
+ <?xml version="1.0" encoding="utf-8"?>
62
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
63
+ android:orientation="vertical"
64
+ android:layout_width="match_parent"
65
+ android:layout_height="match_parent">
66
+ <Button
67
+ android:text="btnSayHello"
68
+ android:layout_width="match_parent"
69
+ android:layout_height="wrap_content"
70
+ android:id="@+id/btnSayHello" />
71
+ <TextView
72
+ android:textAppearance="?android:attr/textAppearanceLarge"
73
+ android:layout_width="match_parent"
74
+ android:layout_height="wrap_content"
75
+ android:id="@+txtMsg" />
76
+ <TextView
77
+ android:text="Large Text"
78
+ android:textAppearance="?android:attr/textAppearanceLarge"
79
+ android:layout_width="match_parent"
80
+ android:layout_height="wrap_content"
81
+ android:id="@+id/textMsg" />
82
+ </LinearLayout>
58
83
  ```

1

コードの追加(返信ではできないため)

2017/12/24 12:22

投稿

mercurian-teto
mercurian-teto

スコア75

title CHANGED
File without changes
body CHANGED
@@ -16,4 +16,43 @@
16
16
 
17
17
  Resource.Designer.csに何か記述するかと推測されるのですが、
18
18
  何を書けばいいのかさっぱりわかりません。
19
- どうすればエラーが解けるか回答お願いします。
19
+ どうすればエラーが解けるか回答お願いします。
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ 追記1
29
+ MainActivity.csのコードです。
30
+ ```C#
31
+ using Android.App;
32
+ using Android.Widget;
33
+ using Android.OS;
34
+
35
+ namespace anti_offtime
36
+ {
37
+ [Activity(Label = "DroidSample", MainLauncher = true, Icon = "@drawable/icon")]
38
+ public class MainActivity : Activity
39
+ {
40
+
41
+ protected override void OnCreate(Bundle bundle)
42
+ {
43
+ base.OnCreate(bundle);
44
+
45
+ // Set our view from the "main" layout resource
46
+ SetContentView(Resource.Layout.Main);
47
+
48
+ Button btnM = FindViewById<Button>(Resource.Id.btnSayHello);
49
+ TextView txtV = FindViewById<TextView>(Resource.Id.txtMsg);
50
+
51
+ btnM.Click += delegate
52
+ {
53
+ txtV.Text = "こんにちは";
54
+ };
55
+ }
56
+ }
57
+ }
58
+ ```