質問編集履歴

8

更新

2016/10/01 02:18

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -16,6 +16,8 @@
16
16
 
17
17
  import android.support.v4.app.Fragment;
18
18
 
19
+ import android.support.v4.app.FragmentManager;
20
+
19
21
  import android.view.LayoutInflater;
20
22
 
21
23
  import android.view.View;
@@ -76,7 +78,7 @@
76
78
 
77
79
 
78
80
 
79
-
81
+
80
82
 
81
83
  //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
82
84
 
@@ -122,6 +124,8 @@
122
124
 
123
125
 
124
126
 
127
+
128
+
125
129
  Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
126
130
 
127
131
  }else {
@@ -134,17 +138,27 @@
134
138
 
135
139
 
136
140
 
141
+ // ActivityからFragmentを取得
142
+
143
+ FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
144
+
145
+ Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
146
+
147
+ // FragmentのViewを取得
148
+
149
+ View view = fragment.getView();
150
+
137
151
  //この下のコードに Can not resolve method 'findViewById'が出ます。
138
152
 
139
153
 
140
154
 
141
- mInputMessage = (EditText)findViewById(R.id.input_message);//ユーザーが入力するフィールド
155
+ mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
142
-
156
+
143
- mSendMessage = (Button) findViewById(R.id.send_message);//SENDボタン
157
+ mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
144
-
158
+
145
- mMessageLog = (LinearLayout)findViewById(R.id.message_log);//入力履歴を表示するレイアウト
159
+ mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
146
-
160
+
147
- mMemoMessage = (TextView) findViewById(R.id.memo_message);//メモの履歴
161
+ mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
148
162
 
149
163
  //この次はデータベースや
150
164
 
@@ -164,6 +178,8 @@
164
178
 
165
179
 
166
180
 
181
+
182
+
167
183
  ```fragment_my_fragment2.xmlです。
168
184
 
169
185
  ```xml
@@ -206,7 +222,7 @@
206
222
 
207
223
  android:layout_toLeftOf="@+id/send_message"
208
224
 
209
- android:layout_toStart0f="@+id/send_message" />
225
+ android:layout_toStartOf="@+id/send_message" />
210
226
 
211
227
 
212
228
 
@@ -283,51 +299,3 @@
283
299
 
284
300
 
285
301
  どうぞよろしくお願いします。
286
-
287
-
288
-
289
- このように変更しました。
290
-
291
- ```java
292
-
293
- // ActivityからFragmentを取得
294
-
295
- FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
296
-
297
- Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
298
-
299
- // FragmentのViewを取得
300
-
301
- View view = fragment.getView();
302
-
303
- //この下のコードに Can not resolve method 'findViewById'が出ます。
304
-
305
-
306
-
307
- mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
308
-
309
- mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
310
-
311
- mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
312
-
313
- mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
314
-
315
- ```
316
-
317
- しかしこのようなエラーが出てしまいます。
318
-
319
- ```
320
-
321
- java
322
-
323
- Error:Execution failed for task ':app:processDebugResources'.
324
-
325
- > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/endoutaichi/Library/Android/sdk/build-tools/23.0.3/aapt'' finished with non-zero exit value 1
326
-
327
- ```
328
-
329
- ```java
330
-
331
- Error:(13) No resource identifier found for attribute 'layout_toStart0f' in package 'android'
332
-
333
- ```

7

アドバイスの結果を表示

2016/10/01 02:18

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -283,3 +283,51 @@
283
283
 
284
284
 
285
285
  どうぞよろしくお願いします。
286
+
287
+
288
+
289
+ このように変更しました。
290
+
291
+ ```java
292
+
293
+ // ActivityからFragmentを取得
294
+
295
+ FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
296
+
297
+ Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
298
+
299
+ // FragmentのViewを取得
300
+
301
+ View view = fragment.getView();
302
+
303
+ //この下のコードに Can not resolve method 'findViewById'が出ます。
304
+
305
+
306
+
307
+ mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
308
+
309
+ mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
310
+
311
+ mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
312
+
313
+ mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
314
+
315
+ ```
316
+
317
+ しかしこのようなエラーが出てしまいます。
318
+
319
+ ```
320
+
321
+ java
322
+
323
+ Error:Execution failed for task ':app:processDebugResources'.
324
+
325
+ > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/endoutaichi/Library/Android/sdk/build-tools/23.0.3/aapt'' finished with non-zero exit value 1
326
+
327
+ ```
328
+
329
+ ```java
330
+
331
+ Error:(13) No resource identifier found for attribute 'layout_toStart0f' in package 'android'
332
+
333
+ ```

6

コードの追加

2016/10/01 01:41

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- Fragmentのjavaクラスです。
5
+ MyFragmentのjavaクラスです。
6
6
 
7
7
  ```java
8
8
 
@@ -164,6 +164,122 @@
164
164
 
165
165
 
166
166
 
167
+ ```fragment_my_fragment2.xmlです。
168
+
169
+ ```xml
170
+
171
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
172
+
173
+ xmlns:tools="http://schemas.android.com/tools"
174
+
175
+ android:layout_width="match_parent"
176
+
177
+ android:layout_height="match_parent"
178
+
179
+ android:orientation="vertical"
180
+
181
+ android:paddingBottom="@dimen/activity_vertical_margin"
182
+
183
+ android:paddingLeft="@dimen/activity_horizontal_margin"
184
+
185
+ android:paddingRight="@dimen/activity_horizontal_margin"
186
+
187
+ android:paddingTop="@dimen/activity_vertical_margin"
188
+
189
+ tools:context="com.example.kanehiro.fragmentapplication.MyFragment2">
190
+
191
+
192
+
193
+
194
+
195
+ <EditText
196
+
197
+ android:layout_width="wrap_content"
198
+
199
+ android:layout_height="wrap_content"
200
+
201
+ android:id="@+id/input_message"
202
+
203
+ android:layout_alignParentLeft="true"
204
+
205
+ android:layout_alignParentStart="true"
206
+
207
+ android:layout_toLeftOf="@+id/send_message"
208
+
209
+ android:layout_toStart0f="@+id/send_message" />
210
+
211
+
212
+
213
+
214
+
215
+ <Button
216
+
217
+ android:id="@+id/send_message"
218
+
219
+ android:layout_width="wrap_content"
220
+
221
+ android:layout_height="wrap_content"
222
+
223
+ android:layout_alignParentEnd="true"
224
+
225
+ android:layout_alignParentRight="true"
226
+
227
+ android:text="SEND"/>
228
+
229
+
230
+
231
+ <ScrollView
232
+
233
+ android:layout_width="fill_parent"
234
+
235
+ android:layout_height="fill_parent"
236
+
237
+ android:layout_alignParentLeft="true"
238
+
239
+ android:layout_alignParentStart="true"
240
+
241
+ android:layout_below="@+id/input_message">
242
+
243
+ <LinearLayout
244
+
245
+ android:layout_width="fill_parent"
246
+
247
+ android:layout_height="wrap_content"
248
+
249
+ android:orientation="vertical"
250
+
251
+ android:id="@+id/message_log">
252
+
253
+
254
+
255
+ <TextView
256
+
257
+ android:id="@+id/memo_message"
258
+
259
+ android:layout_width="wrap_content"
260
+
261
+ android:layout_height="wrap_content"
262
+
263
+ android:layout_gravity="start"
264
+
265
+ android:text="memo一覧"/>
266
+
267
+
268
+
269
+ </LinearLayout>
270
+
271
+ </ScrollView>
272
+
273
+
274
+
275
+ </RelativeLayout>
276
+
277
+
278
+
279
+
280
+
167
281
  ```
168
282
 
283
+
284
+
169
285
  どうぞよろしくお願いします。

5

誤字

2016/10/01 00:40

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -122,10 +122,6 @@
122
122
 
123
123
 
124
124
 
125
- //この下のコードにCan not resolve method 'makeText'が出ます。
126
-
127
-
128
-
129
125
  Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
130
126
 
131
127
  }else {

4

誤字

2016/09/30 23:39

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -76,19 +76,23 @@
76
76
 
77
77
 
78
78
 
79
-
79
+
80
80
 
81
81
  //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
82
82
 
83
83
 
84
84
 
85
- view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
85
+ view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
86
86
 
87
87
  @Override
88
88
 
89
- public void onClick(View v) {
89
+ public void onClick(View v){
90
90
 
91
-
91
+
92
+
93
+
94
+
95
+
92
96
 
93
97
  }
94
98
 
@@ -104,15 +108,15 @@
104
108
 
105
109
  @Override
106
110
 
107
- public void onClick(View view) {
111
+ public void onClick(View v) {
108
112
 
109
113
 
110
114
 
111
- if (v.equals(mSendMessage)) {
115
+ if(v.equals(mSendMessage)) {
112
116
 
113
117
 
114
118
 
115
- if (mSendMessage == null || mSendMessage.length() == 0) {
119
+ if(mSendMessage==null||mSendMessage.length()==0){
116
120
 
117
121
 
118
122
 
@@ -122,9 +126,9 @@
122
126
 
123
127
 
124
128
 
125
- Toast.makeText(getActivity(), "文字が入力されていません", Toast.LENGTH_LONG).show();
129
+ Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
126
130
 
127
- } else {
131
+ }else {
128
132
 
129
133
  //新しくエラーを消すために作った場所
130
134
 
@@ -134,13 +138,29 @@
134
138
 
135
139
 
136
140
 
141
+ //この下のコードに Can not resolve method 'findViewById'が出ます。
137
142
 
143
+
144
+
145
+ mInputMessage = (EditText)findViewById(R.id.input_message);//ユーザーが入力するフィールド
146
+
147
+ mSendMessage = (Button) findViewById(R.id.send_message);//SENDボタン
148
+
149
+ mMessageLog = (LinearLayout)findViewById(R.id.message_log);//入力履歴を表示するレイアウト
150
+
151
+ mMemoMessage = (TextView) findViewById(R.id.memo_message);//メモの履歴
152
+
153
+ //この次はデータベースや
154
+
155
+ mSendMessage.setOnClickListener(this);
138
156
 
139
157
  }
140
158
 
141
159
  }
142
160
 
143
-
161
+
162
+
163
+
144
164
 
145
165
  }
146
166
 

3

誤字

2016/09/30 23:37

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -1,153 +1,3 @@
1
- FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
2
-
3
-
4
-
5
- Fragmentのjavaクラスです。
6
-
7
- ```java
8
-
9
- package com.example.kanehiro.fragmentapplication;
10
-
11
-
12
-
13
-
14
-
15
- import android.os.Bundle;
16
-
17
- import android.support.v4.app.Fragment;
18
-
19
- import android.view.LayoutInflater;
20
-
21
- import android.view.View;
22
-
23
- import android.view.ViewGroup;
24
-
25
- import android.widget.Button;
26
-
27
- import android.widget.EditText;
28
-
29
- import android.widget.LinearLayout;
30
-
31
- import android.widget.TextView;
32
-
33
- import android.widget.Toast;
34
-
35
-
36
-
37
-
38
-
39
- public class MyFragment2 extends Fragment implements View.OnClickListener {
40
-
41
-
42
-
43
- //とりあえずここにさらなるステップの変数
44
-
45
- private EditText mInputMessage;
46
-
47
- private Button mSendMessage;
48
-
49
- private LinearLayout mMessageLog;
50
-
51
- private TextView mMemoMessage;
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
- public MyFragment2() {
60
-
61
-
62
-
63
- }
64
-
65
-
66
-
67
-
68
-
69
- @Override
70
-
71
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
72
-
73
- Bundle savedInstanceState) {
74
-
75
- View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
76
-
77
-
78
-
79
-
80
-
81
- //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
82
-
83
-
84
-
85
- view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
86
-
87
- @Override
88
-
89
- public void onClick(View v) {
90
-
91
-
92
-
93
- }
94
-
95
- });
96
-
97
- return view;
98
-
99
- }
100
-
101
-
102
-
103
-
104
-
105
- @Override
106
-
107
- public void onClick(View view) {
108
-
109
-
110
-
111
- if (v.equals(mSendMessage)) {
112
-
113
-
114
-
115
- if (mSendMessage == null || mSendMessage.length() == 0) {
116
-
117
-
118
-
119
-
120
-
121
- //この下のコードにCan not resolve method 'makeText'が出ます。
122
-
123
-
124
-
125
- Toast.makeText(getActivity(), "文字が入力されていません。", Toast.LENGTH_LONG).show();
126
-
127
- } else {
128
-
129
- //新しくエラーを消すために作った場所
130
-
131
- //XMLのViewを初期化する
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
- }
140
-
141
- }
142
-
143
-
144
-
145
- }
146
-
147
- }
148
-
149
-
150
-
151
1
  どうぞよろしくお願いします。FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
152
2
 
153
3
 
@@ -298,4 +148,6 @@
298
148
 
299
149
 
300
150
 
151
+ ```
152
+
301
153
  どうぞよろしくお願いします。

2

詳細の変更

2016/09/30 23:36

投稿

edoooooo
edoooooo

スコア476

test CHANGED
@@ -1 +1 @@
1
- FragmentのjavaクラスでmakeText()やfindViewById()を使いたいのですがどうすれば良いのでしょうか?
1
+ FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
test CHANGED
@@ -74,15 +74,21 @@
74
74
 
75
75
  View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
76
76
 
77
+
78
+
79
+
80
+
81
+ //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
82
+
83
+
84
+
77
- view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
85
+ view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
78
86
 
79
87
  @Override
80
88
 
81
- public void onClick(View v){
89
+ public void onClick(View v) {
82
-
83
- getFragmentManager().popBackStack();
90
+
84
-
85
-
91
+
86
92
 
87
93
  }
88
94
 
@@ -98,53 +104,193 @@
98
104
 
99
105
  @Override
100
106
 
107
+ public void onClick(View view) {
108
+
109
+
110
+
111
+ if (v.equals(mSendMessage)) {
112
+
113
+
114
+
115
+ if (mSendMessage == null || mSendMessage.length() == 0) {
116
+
117
+
118
+
119
+
120
+
121
+ //この下のコードにCan not resolve method 'makeText'が出ます。
122
+
123
+
124
+
125
+ Toast.makeText(getActivity(), "文字が入力されていません。", Toast.LENGTH_LONG).show();
126
+
127
+ } else {
128
+
129
+ //新しくエラーを消すために作った場所
130
+
131
+ //XMLのViewを初期化する
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+ }
140
+
141
+ }
142
+
143
+
144
+
145
+ }
146
+
147
+ }
148
+
149
+
150
+
151
+ どうぞよろしくお願いします。FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
152
+
153
+
154
+
155
+ Fragmentのjavaクラスです。
156
+
157
+ ```java
158
+
159
+ package com.example.kanehiro.fragmentapplication;
160
+
161
+
162
+
163
+
164
+
165
+ import android.os.Bundle;
166
+
167
+ import android.support.v4.app.Fragment;
168
+
169
+ import android.view.LayoutInflater;
170
+
171
+ import android.view.View;
172
+
173
+ import android.view.ViewGroup;
174
+
175
+ import android.widget.Button;
176
+
177
+ import android.widget.EditText;
178
+
179
+ import android.widget.LinearLayout;
180
+
181
+ import android.widget.TextView;
182
+
183
+ import android.widget.Toast;
184
+
185
+
186
+
187
+
188
+
189
+ public class MyFragment2 extends Fragment implements View.OnClickListener {
190
+
191
+
192
+
193
+ //とりあえずここにさらなるステップの変数
194
+
195
+ private EditText mInputMessage;
196
+
197
+ private Button mSendMessage;
198
+
199
+ private LinearLayout mMessageLog;
200
+
201
+ private TextView mMemoMessage;
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+ public MyFragment2() {
210
+
211
+
212
+
213
+ }
214
+
215
+
216
+
217
+
218
+
219
+ @Override
220
+
221
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
222
+
223
+ Bundle savedInstanceState) {
224
+
225
+ View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
226
+
227
+
228
+
229
+
230
+
231
+ //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
232
+
233
+
234
+
235
+ view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
236
+
237
+ @Override
238
+
101
- public void onClick(View v){
239
+ public void onClick(View v) {
102
-
103
- if(v.equals(mSendMessage)) {
104
-
105
-
106
-
107
- if(mSendMessage==null||mSendMessage.length()==0){
108
240
 
109
241
 
110
242
 
111
-
243
+ }
244
+
112
-
245
+ });
246
+
113
-
247
+ return view;
248
+
114
-
249
+ }
250
+
251
+
252
+
253
+
254
+
255
+ @Override
256
+
257
+ public void onClick(View view) {
258
+
259
+
260
+
261
+ if (v.equals(mSendMessage)) {
262
+
263
+
264
+
265
+ if (mSendMessage == null || mSendMessage.length() == 0) {
266
+
267
+
268
+
269
+
270
+
271
+ //この下のコードにCan not resolve method 'makeText'が出ます。
272
+
273
+
274
+
115
- Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
275
+ Toast.makeText(getActivity(), "文字が入力されていません", Toast.LENGTH_LONG).show();
116
-
276
+
117
- }else {
277
+ } else {
118
278
 
119
279
  //新しくエラーを消すために作った場所
120
280
 
121
281
  //XMLのViewを初期化する
122
282
 
123
-
124
-
125
-
126
-
127
- //この下のコードに Can not resolve method 'findViewById'が出ます。
283
+
128
-
129
-
130
-
131
- mInputMessage = (EditText) findViewById(R.id.input_message);//ユーザーが入力するフィールド
284
+
132
-
133
- mSendMessage = (Button) findViewById(R.id.send_message);//SENDボタン
285
+
134
-
135
- mMessageLog = (LinearLayout) findViewById(R.id.message_log);//入力履歴を表示するレイアウト
286
+
136
-
137
- mMemoMessage = (TextView) findViewById(R.id.memo_message);//メモの履歴
287
+
138
-
139
- //この次はデータベースや
140
-
141
- mSendMessage.setOnClickListener(this);
142
288
 
143
289
  }
144
290
 
145
291
  }
146
292
 
147
-
293
+
148
294
 
149
295
  }
150
296
 
@@ -152,6 +298,4 @@
152
298
 
153
299
 
154
300
 
155
- ```
156
-
157
301
  どうぞよろしくお願いします。

1

詳細の変更

2016/09/30 23:10

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- FragmentのjavaクラスでmakeText()やfindViewById()を使いたいのですがどうすれば良いのでしょうか?
1
+ FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
2
2
 
3
3
 
4
4
 
@@ -110,11 +110,9 @@
110
110
 
111
111
 
112
112
 
113
- //この下のコードにCan not resolve method 'makeText'が出ます。
114
-
115
113
 
116
114
 
117
- Toast.makeText(this,"文字が入力されていません",Toast.LENGTH_SHORT).show();
115
+ Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
118
116
 
119
117
  }else {
120
118