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

質問編集履歴

8

更新

2016/10/01 02:18

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  import android.os.Bundle;
9
9
  import android.support.v4.app.Fragment;
10
+ import android.support.v4.app.FragmentManager;
10
11
  import android.view.LayoutInflater;
11
12
  import android.view.View;
12
13
  import android.view.ViewGroup;
@@ -37,7 +38,7 @@
37
38
  Bundle savedInstanceState) {
38
39
  View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
39
40
 
40
-
41
+
41
42
  //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
42
43
 
43
44
  view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
@@ -60,18 +61,24 @@
60
61
  if(mSendMessage==null||mSendMessage.length()==0){
61
62
 
62
63
 
64
+
63
65
  Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
64
66
  }else {
65
67
  //新しくエラーを消すために作った場所
66
68
  //XMLのViewを初期化する
67
69
 
68
70
 
71
+ // ActivityからFragmentを取得
72
+ FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
73
+ Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
74
+ // FragmentのViewを取得
75
+ View view = fragment.getView();
69
76
  //この下のコードに Can not resolve method 'findViewById'が出ます。
70
77
 
71
- mInputMessage = (EditText)findViewById(R.id.input_message);//ユーザーが入力するフィールド
78
+ mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
72
- mSendMessage = (Button) findViewById(R.id.send_message);//SENDボタン
79
+ mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
73
- mMessageLog = (LinearLayout)findViewById(R.id.message_log);//入力履歴を表示するレイアウト
80
+ mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
74
- mMemoMessage = (TextView) findViewById(R.id.memo_message);//メモの履歴
81
+ mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
75
82
  //この次はデータベースや
76
83
  mSendMessage.setOnClickListener(this);
77
84
  }
@@ -81,6 +88,7 @@
81
88
  }
82
89
  }
83
90
 
91
+
84
92
  ```fragment_my_fragment2.xmlです。
85
93
  ```xml
86
94
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
@@ -102,7 +110,7 @@
102
110
  android:layout_alignParentLeft="true"
103
111
  android:layout_alignParentStart="true"
104
112
  android:layout_toLeftOf="@+id/send_message"
105
- android:layout_toStart0f="@+id/send_message" />
113
+ android:layout_toStartOf="@+id/send_message" />
106
114
 
107
115
 
108
116
  <Button
@@ -140,28 +148,4 @@
140
148
 
141
149
  ```
142
150
 
143
- どうぞよろしくお願いします。
144
-
145
- このように変更しました。
146
- ```java
147
- // ActivityからFragmentを取得
148
- FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
149
- Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
150
- // FragmentのViewを取得
151
- View view = fragment.getView();
152
- //この下のコードに Can not resolve method 'findViewById'が出ます。
153
-
154
- mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
155
- mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
156
- mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
157
- mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
158
- ```
159
- しかしこのようなエラーが出てしまいます。
160
- ```
161
- java
162
- Error:Execution failed for task ':app:processDebugResources'.
163
- > 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
164
- ```
165
- ```java
166
- Error:(13) No resource identifier found for attribute 'layout_toStart0f' in package 'android'
167
- ```
151
+ どうぞよろしくお願いします。

7

アドバイスの結果を表示

2016/10/01 02:18

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -140,4 +140,28 @@
140
140
 
141
141
  ```
142
142
 
143
- どうぞよろしくお願いします。
143
+ どうぞよろしくお願いします。
144
+
145
+ このように変更しました。
146
+ ```java
147
+ // ActivityからFragmentを取得
148
+ FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
149
+ Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
150
+ // FragmentのViewを取得
151
+ View view = fragment.getView();
152
+ //この下のコードに Can not resolve method 'findViewById'が出ます。
153
+
154
+ mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
155
+ mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
156
+ mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
157
+ mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
158
+ ```
159
+ しかしこのようなエラーが出てしまいます。
160
+ ```
161
+ java
162
+ Error:Execution failed for task ':app:processDebugResources'.
163
+ > 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
164
+ ```
165
+ ```java
166
+ Error:(13) No resource identifier found for attribute 'layout_toStart0f' in package 'android'
167
+ ```

6

コードの追加

2016/10/01 01:41

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,6 @@
1
1
  どうぞよろしくお願いします。FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
2
2
 
3
- Fragmentのjavaクラスです。
3
+ MyFragmentのjavaクラスです。
4
4
  ```java
5
5
  package com.example.kanehiro.fragmentapplication;
6
6
 
@@ -81,5 +81,63 @@
81
81
  }
82
82
  }
83
83
 
84
+ ```fragment_my_fragment2.xmlです。
85
+ ```xml
86
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
87
+ xmlns:tools="http://schemas.android.com/tools"
88
+ android:layout_width="match_parent"
89
+ android:layout_height="match_parent"
90
+ android:orientation="vertical"
91
+ android:paddingBottom="@dimen/activity_vertical_margin"
92
+ android:paddingLeft="@dimen/activity_horizontal_margin"
93
+ android:paddingRight="@dimen/activity_horizontal_margin"
94
+ android:paddingTop="@dimen/activity_vertical_margin"
95
+ tools:context="com.example.kanehiro.fragmentapplication.MyFragment2">
96
+
97
+
98
+ <EditText
99
+ android:layout_width="wrap_content"
100
+ android:layout_height="wrap_content"
101
+ android:id="@+id/input_message"
102
+ android:layout_alignParentLeft="true"
103
+ android:layout_alignParentStart="true"
104
+ android:layout_toLeftOf="@+id/send_message"
105
+ android:layout_toStart0f="@+id/send_message" />
106
+
107
+
108
+ <Button
109
+ android:id="@+id/send_message"
110
+ android:layout_width="wrap_content"
111
+ android:layout_height="wrap_content"
112
+ android:layout_alignParentEnd="true"
113
+ android:layout_alignParentRight="true"
114
+ android:text="SEND"/>
115
+
116
+ <ScrollView
117
+ android:layout_width="fill_parent"
118
+ android:layout_height="fill_parent"
119
+ android:layout_alignParentLeft="true"
120
+ android:layout_alignParentStart="true"
121
+ android:layout_below="@+id/input_message">
122
+ <LinearLayout
123
+ android:layout_width="fill_parent"
124
+ android:layout_height="wrap_content"
125
+ android:orientation="vertical"
126
+ android:id="@+id/message_log">
127
+
128
+ <TextView
129
+ android:id="@+id/memo_message"
130
+ android:layout_width="wrap_content"
131
+ android:layout_height="wrap_content"
132
+ android:layout_gravity="start"
133
+ android:text="memo一覧"/>
134
+
135
+ </LinearLayout>
136
+ </ScrollView>
137
+
138
+ </RelativeLayout>
139
+
140
+
84
141
  ```
142
+
85
143
  どうぞよろしくお願いします。

5

誤字

2016/10/01 00:40

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -60,8 +60,6 @@
60
60
  if(mSendMessage==null||mSendMessage.length()==0){
61
61
 
62
62
 
63
- //この下のコードにCan not resolve method 'makeText'が出ます。
64
-
65
63
  Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
66
64
  }else {
67
65
  //新しくエラーを消すために作った場所

4

誤字

2016/09/30 23:39

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -37,13 +37,15 @@
37
37
  Bundle savedInstanceState) {
38
38
  View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
39
39
 
40
-
40
+
41
41
  //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
42
42
 
43
- view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
43
+ view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
44
44
  @Override
45
- public void onClick(View v) {
45
+ public void onClick(View v){
46
-
46
+
47
+
48
+
47
49
  }
48
50
  });
49
51
  return view;
@@ -51,25 +53,33 @@
51
53
 
52
54
 
53
55
  @Override
54
- public void onClick(View view) {
56
+ public void onClick(View v) {
55
57
 
56
- if (v.equals(mSendMessage)) {
58
+ if(v.equals(mSendMessage)) {
57
59
 
58
- if (mSendMessage == null || mSendMessage.length() == 0) {
60
+ if(mSendMessage==null||mSendMessage.length()==0){
59
61
 
60
62
 
61
63
  //この下のコードにCan not resolve method 'makeText'が出ます。
62
64
 
63
- Toast.makeText(getActivity(), "文字が入力されていません", Toast.LENGTH_LONG).show();
65
+ Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
64
- } else {
66
+ }else {
65
67
  //新しくエラーを消すために作った場所
66
68
  //XMLのViewを初期化する
67
69
 
68
70
 
71
+ //この下のコードに Can not resolve method 'findViewById'が出ます。
69
72
 
73
+ mInputMessage = (EditText)findViewById(R.id.input_message);//ユーザーが入力するフィールド
74
+ mSendMessage = (Button) findViewById(R.id.send_message);//SENDボタン
75
+ mMessageLog = (LinearLayout)findViewById(R.id.message_log);//入力履歴を表示するレイアウト
76
+ mMemoMessage = (TextView) findViewById(R.id.memo_message);//メモの履歴
77
+ //この次はデータベースや
78
+ mSendMessage.setOnClickListener(this);
70
79
  }
71
80
  }
72
-
81
+
82
+
73
83
  }
74
84
  }
75
85
 

3

誤字

2016/09/30 23:37

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -1,78 +1,3 @@
1
- FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
2
-
3
- Fragmentのjavaクラスです。
4
- ```java
5
- package com.example.kanehiro.fragmentapplication;
6
-
7
-
8
- import android.os.Bundle;
9
- import android.support.v4.app.Fragment;
10
- import android.view.LayoutInflater;
11
- import android.view.View;
12
- import android.view.ViewGroup;
13
- import android.widget.Button;
14
- import android.widget.EditText;
15
- import android.widget.LinearLayout;
16
- import android.widget.TextView;
17
- import android.widget.Toast;
18
-
19
-
20
- public class MyFragment2 extends Fragment implements View.OnClickListener {
21
-
22
- //とりあえずここにさらなるステップの変数
23
- private EditText mInputMessage;
24
- private Button mSendMessage;
25
- private LinearLayout mMessageLog;
26
- private TextView mMemoMessage;
27
-
28
-
29
-
30
- public MyFragment2() {
31
-
32
- }
33
-
34
-
35
- @Override
36
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
37
- Bundle savedInstanceState) {
38
- View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
39
-
40
-
41
- //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
42
-
43
- view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
44
- @Override
45
- public void onClick(View v) {
46
-
47
- }
48
- });
49
- return view;
50
- }
51
-
52
-
53
- @Override
54
- public void onClick(View view) {
55
-
56
- if (v.equals(mSendMessage)) {
57
-
58
- if (mSendMessage == null || mSendMessage.length() == 0) {
59
-
60
-
61
- //この下のコードにCan not resolve method 'makeText'が出ます。
62
-
63
- Toast.makeText(getActivity(), "文字が入力されていません。", Toast.LENGTH_LONG).show();
64
- } else {
65
- //新しくエラーを消すために作った場所
66
- //XMLのViewを初期化する
67
-
68
-
69
-
70
- }
71
- }
72
-
73
- }
74
- }
75
-
76
1
  どうぞよろしくお願いします。FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
77
2
 
78
3
  Fragmentのjavaクラスです。
@@ -148,4 +73,5 @@
148
73
  }
149
74
  }
150
75
 
76
+ ```
151
77
  どうぞよろしくお願いします。

2

詳細の変更

2016/09/30 23:36

投稿

edoooooo
edoooooo

スコア478

title CHANGED
@@ -1,1 +1,1 @@
1
- FragmentのjavaクラスでmakeText()やfindViewById()を使いたいのですがどうすれば良いのでしょうか?
1
+ FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
body CHANGED
@@ -36,11 +36,14 @@
36
36
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
37
37
  Bundle savedInstanceState) {
38
38
  View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
39
+
40
+
41
+ //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
42
+
39
- view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
43
+ view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
40
44
  @Override
41
- public void onClick(View v){
45
+ public void onClick(View v) {
42
- getFragmentManager().popBackStack();
46
+
43
-
44
47
  }
45
48
  });
46
49
  return view;
@@ -48,32 +51,101 @@
48
51
 
49
52
 
50
53
  @Override
51
- public void onClick(View v){
54
+ public void onClick(View view) {
52
- if(v.equals(mSendMessage)) {
53
55
 
56
+ if (v.equals(mSendMessage)) {
57
+
54
- if(mSendMessage==null||mSendMessage.length()==0){
58
+ if (mSendMessage == null || mSendMessage.length() == 0) {
59
+
60
+
55
-
61
+ //この下のコードにCan not resolve method 'makeText'が出ます。
56
-
57
-
62
+
58
- Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
63
+ Toast.makeText(getActivity(), "文字が入力されていません", Toast.LENGTH_LONG).show();
59
- }else {
64
+ } else {
60
65
  //新しくエラーを消すために作った場所
61
66
  //XMLのViewを初期化する
62
-
63
-
64
- //この下のコードに Can not resolve method 'findViewById'が出ます。
67
+
65
-
66
- mInputMessage = (EditText) findViewById(R.id.input_message);//ユーザーが入力するフィールド
68
+
67
- mSendMessage = (Button) findViewById(R.id.send_message);//SENDボタン
69
+
68
- mMessageLog = (LinearLayout) findViewById(R.id.message_log);//入力履歴を表示するレイアウト
69
- mMemoMessage = (TextView) findViewById(R.id.memo_message);//メモの履歴
70
- //この次はデータベースや
71
- mSendMessage.setOnClickListener(this);
72
70
  }
73
71
  }
72
+
73
+ }
74
+ }
74
75
 
76
+ どうぞよろしくお願いします。FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
77
+
78
+ Fragmentのjavaクラスです。
79
+ ```java
80
+ package com.example.kanehiro.fragmentapplication;
81
+
82
+
83
+ import android.os.Bundle;
84
+ import android.support.v4.app.Fragment;
85
+ import android.view.LayoutInflater;
86
+ import android.view.View;
87
+ import android.view.ViewGroup;
88
+ import android.widget.Button;
89
+ import android.widget.EditText;
90
+ import android.widget.LinearLayout;
91
+ import android.widget.TextView;
92
+ import android.widget.Toast;
93
+
94
+
95
+ public class MyFragment2 extends Fragment implements View.OnClickListener {
96
+
97
+ //とりあえずここにさらなるステップの変数
98
+ private EditText mInputMessage;
99
+ private Button mSendMessage;
100
+ private LinearLayout mMessageLog;
101
+ private TextView mMemoMessage;
102
+
103
+
104
+
105
+ public MyFragment2() {
106
+
75
107
  }
108
+
109
+
110
+ @Override
111
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
112
+ Bundle savedInstanceState) {
113
+ View view=inflater.inflate(R.layout.fragment_my_fragment2,container,false);
114
+
115
+
116
+ //何に使うのかわからん Button btn = (Button) view.findViewById(R.id.button);
117
+
118
+ view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
119
+ @Override
120
+ public void onClick(View v) {
121
+
122
+ }
123
+ });
124
+ return view;
125
+ }
126
+
127
+
128
+ @Override
129
+ public void onClick(View view) {
130
+
131
+ if (v.equals(mSendMessage)) {
132
+
133
+ if (mSendMessage == null || mSendMessage.length() == 0) {
134
+
135
+
136
+ //この下のコードにCan not resolve method 'makeText'が出ます。
137
+
138
+ Toast.makeText(getActivity(), "文字が入力されていません。", Toast.LENGTH_LONG).show();
139
+ } else {
140
+ //新しくエラーを消すために作った場所
141
+ //XMLのViewを初期化する
142
+
143
+
144
+
145
+ }
146
+ }
147
+
148
+ }
76
149
  }
77
150
 
78
- ```
79
151
  どうぞよろしくお願いします。

1

詳細の変更

2016/09/30 23:10

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- FragmentのjavaクラスでmakeText()やfindViewById()を使いたいのですがどうすれば良いのでしょうか?
1
+ FragmentのjavaクラスでfindViewById()を使いたいのですがどうすれば良いのでしょうか?
2
2
 
3
3
  Fragmentのjavaクラスです。
4
4
  ```java
@@ -54,9 +54,8 @@
54
54
  if(mSendMessage==null||mSendMessage.length()==0){
55
55
 
56
56
 
57
- //この下のコードにCan not resolve method 'makeText'が出ます。
58
57
 
59
- Toast.makeText(this,"文字が入力されていません",Toast.LENGTH_SHORT).show();
58
+ Toast.makeText(getActivity(),"文字が入力されていません",Toast.LENGTH_SHORT).show();
60
59
  }else {
61
60
  //新しくエラーを消すために作った場所
62
61
  //XMLのViewを初期化する