質問編集履歴

3

明示

2016/08/11 06:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  Androidのアプリ開発を始めました。
2
2
 
3
- EditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすればfindViewByIdでnullではなく目当てのEditTextを取得できるでしょうか?
3
+ screenNameのEditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすればfindViewByIdでnullではなくscreenNameのEditTextを取得できるでしょうか?
4
4
 
5
5
 
6
6
 

2

コード追加

2016/08/11 06:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,4 +4,256 @@
4
4
 
5
5
 
6
6
 
7
+ 追記(ソースコード)
8
+
9
+
10
+
11
+ ```java
12
+
13
+ package tk.surume.android.misqforandroid;
14
+
15
+
16
+
17
+ import android.net.Uri;
18
+
19
+ import android.support.v7.app.AppCompatActivity;
20
+
21
+ import android.os.Bundle;
22
+
23
+ import android.view.View;
24
+
25
+ import android.widget.EditText;
26
+
27
+ import android.widget.Toast;
28
+
29
+
30
+
31
+ import com.google.android.gms.appindexing.Action;
32
+
33
+ import com.google.android.gms.appindexing.AppIndex;
34
+
35
+ import com.google.android.gms.common.api.GoogleApiClient;
36
+
37
+
38
+
39
+ public class LoginActivity extends AppCompatActivity {
40
+
41
+
42
+
43
+ /**
44
+
45
+ * ATTENTION: This was auto-generated to implement the App Indexing API.
46
+
47
+ * See https://g.co/AppIndexing/AndroidStudio for more information.
48
+
49
+ */
50
+
51
+ private GoogleApiClient client;
52
+
53
+
54
+
55
+ @Override
56
+
57
+ protected void onCreate(Bundle savedInstanceState) {
58
+
59
+ super.onCreate(savedInstanceState);
60
+
61
+ setContentView(R.layout.activity_login);
62
+
63
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
64
+
65
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
66
+
67
+ client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
68
+
69
+ }
70
+
71
+
72
+
73
+ @Override
74
+
75
+ public void onStart() {
76
+
77
+ super.onStart();
78
+
79
+
80
+
81
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
82
+
83
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
84
+
85
+ client.connect();
86
+
87
+ Action viewAction = Action.newAction(
88
+
89
+ Action.TYPE_VIEW, // TODO: choose an action type.
90
+
91
+ "Login Page", // TODO: Define a title for the content shown.
92
+
93
+ // TODO: If you have web page content that matches this app activity's content,
94
+
95
+ // make sure this auto-generated web page URL is correct.
96
+
97
+ // Otherwise, set the URL to null.
98
+
99
+ Uri.parse("http://host/path"),
100
+
101
+ // TODO: Make sure this auto-generated app URL is correct.
102
+
7
- ソースコード(長くなるのでGistに記述します): [https://gist.github.com/Petitsurume/041425d33471c5e3196ab92f7de57895](https://gist.github.com/Petitsurume/041425d33471c5e3196ab92f7de57895)
103
+ Uri.parse("android-app://tk.surume.android.misqforandroid/http/host/path")
104
+
105
+ );
106
+
107
+ AppIndex.AppIndexApi.start(client, viewAction);
108
+
109
+ }
110
+
111
+
112
+
113
+ @Override
114
+
115
+ public void onStop() {
116
+
117
+ super.onStop();
118
+
119
+
120
+
121
+ // ATTENTION: This was auto-generated to implement the App Indexing API.
122
+
123
+ // See https://g.co/AppIndexing/AndroidStudio for more information.
124
+
125
+ Action viewAction = Action.newAction(
126
+
127
+ Action.TYPE_VIEW, // TODO: choose an action type.
128
+
129
+ "Login Page", // TODO: Define a title for the content shown.
130
+
131
+ // TODO: If you have web page content that matches this app activity's content,
132
+
133
+ // make sure this auto-generated web page URL is correct.
134
+
135
+ // Otherwise, set the URL to null.
136
+
137
+ Uri.parse("http://host/path"),
138
+
139
+ // TODO: Make sure this auto-generated app URL is correct.
140
+
141
+ Uri.parse("android-app://tk.surume.android.misqforandroid/http/host/path")
142
+
143
+ );
144
+
145
+ AppIndex.AppIndexApi.end(client, viewAction);
146
+
147
+ client.disconnect();
148
+
149
+ }
150
+
151
+
152
+
153
+ public void onLoginClicked(View v){
154
+
155
+ EditText screenNameInput = (EditText)findViewById(R.id.screenName);
156
+
157
+ System.out.println(screenNameInput);
158
+
159
+ String screenName = screenNameInput.getText().toString();
160
+
161
+ Toast.makeText(this, screenName, Toast.LENGTH_LONG).show();
162
+
163
+ }
164
+
165
+ }
166
+
167
+ ```
168
+
169
+
170
+
171
+ ```xml
172
+
173
+ <?xml version="1.0" encoding="utf-8"?>
174
+
175
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
176
+
177
+ xmlns:tools="http://schemas.android.com/tools"
178
+
179
+ android:layout_width="match_parent"
180
+
181
+ android:layout_height="match_parent"
182
+
183
+ android:paddingBottom="@dimen/activity_vertical_margin"
184
+
185
+ android:paddingLeft="@dimen/activity_horizontal_margin"
186
+
187
+ android:paddingRight="@dimen/activity_horizontal_margin"
188
+
189
+ android:paddingTop="@dimen/activity_vertical_margin"
190
+
191
+ tools:context="tk.surume.android.misqforandroid.LoginActivity">
192
+
193
+
194
+
195
+ <EditText
196
+
197
+ android:layout_width="wrap_content"
198
+
199
+ android:layout_height="wrap_content"
200
+
201
+ android:id="@+id/screenName"
202
+
203
+ android:layout_alignParentTop="true"
204
+
205
+ android:layout_alignParentStart="true"
206
+
207
+ android:layout_alignParentEnd="true"
208
+
209
+ android:text="*****"
210
+
211
+ android:hint="@string/screen_name" />
212
+
213
+
214
+
215
+ <EditText
216
+
217
+ android:layout_width="wrap_content"
218
+
219
+ android:layout_height="wrap_content"
220
+
221
+ android:inputType="textPassword"
222
+
223
+ android:ems="10"
224
+
225
+ android:id="@+id/password"
226
+
227
+ android:layout_below="@+id/screenName"
228
+
229
+ android:layout_alignParentStart="true"
230
+
231
+ android:layout_alignEnd="@+id/screenName"
232
+
233
+ android:hint="@string/password"
234
+
235
+ android:text="*****" />
236
+
237
+
238
+
239
+ <Button
240
+
241
+ android:layout_width="wrap_content"
242
+
243
+ android:layout_height="wrap_content"
244
+
245
+ android:text="@string/login"
246
+
247
+ android:id="@+id/button"
248
+
249
+ android:layout_below="@+id/password"
250
+
251
+ android:layout_alignEnd="@+id/password"
252
+
253
+ android:layout_alignParentStart="true"
254
+
255
+ android:onClick="onLoginClicked" />
256
+
257
+ </RelativeLayout>
258
+
259
+ ```

1

途中から抜けてたので修正

2016/08/11 05:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  Androidのアプリ開発を始めました。
2
2
 
3
- EditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすれば目
3
+ EditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすればfindViewByIdでnullではなく当てEditTextを取得できるでしょうか?
4
4
 
5
5
 
6
6