質問編集履歴
3
明示
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Androidのアプリ開発を始めました。
|
2
|
-
EditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすればfindViewByIdでnullではなく
|
2
|
+
screenNameのEditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすればfindViewByIdでnullではなくscreenNameのEditTextを取得できるでしょうか?
|
3
3
|
|
4
4
|
追記(ソースコード)
|
5
5
|
|
2
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,130 @@
|
|
1
1
|
Androidのアプリ開発を始めました。
|
2
2
|
EditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすればfindViewByIdでnullではなく目当てのEditTextを取得できるでしょうか?
|
3
3
|
|
4
|
+
追記(ソースコード)
|
5
|
+
|
6
|
+
```java
|
7
|
+
package tk.surume.android.misqforandroid;
|
8
|
+
|
9
|
+
import android.net.Uri;
|
10
|
+
import android.support.v7.app.AppCompatActivity;
|
11
|
+
import android.os.Bundle;
|
12
|
+
import android.view.View;
|
13
|
+
import android.widget.EditText;
|
14
|
+
import android.widget.Toast;
|
15
|
+
|
16
|
+
import com.google.android.gms.appindexing.Action;
|
17
|
+
import com.google.android.gms.appindexing.AppIndex;
|
18
|
+
import com.google.android.gms.common.api.GoogleApiClient;
|
19
|
+
|
20
|
+
public class LoginActivity extends AppCompatActivity {
|
21
|
+
|
22
|
+
/**
|
23
|
+
* ATTENTION: This was auto-generated to implement the App Indexing API.
|
24
|
+
* See https://g.co/AppIndexing/AndroidStudio for more information.
|
25
|
+
*/
|
26
|
+
private GoogleApiClient client;
|
27
|
+
|
28
|
+
@Override
|
29
|
+
protected void onCreate(Bundle savedInstanceState) {
|
30
|
+
super.onCreate(savedInstanceState);
|
31
|
+
setContentView(R.layout.activity_login);
|
32
|
+
// ATTENTION: This was auto-generated to implement the App Indexing API.
|
33
|
+
// See https://g.co/AppIndexing/AndroidStudio for more information.
|
34
|
+
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
|
35
|
+
}
|
36
|
+
|
37
|
+
@Override
|
38
|
+
public void onStart() {
|
39
|
+
super.onStart();
|
40
|
+
|
41
|
+
// ATTENTION: This was auto-generated to implement the App Indexing API.
|
42
|
+
// See https://g.co/AppIndexing/AndroidStudio for more information.
|
43
|
+
client.connect();
|
44
|
+
Action viewAction = Action.newAction(
|
45
|
+
Action.TYPE_VIEW, // TODO: choose an action type.
|
46
|
+
"Login Page", // TODO: Define a title for the content shown.
|
47
|
+
// TODO: If you have web page content that matches this app activity's content,
|
48
|
+
// make sure this auto-generated web page URL is correct.
|
49
|
+
// Otherwise, set the URL to null.
|
50
|
+
Uri.parse("http://host/path"),
|
51
|
+
// TODO: Make sure this auto-generated app URL is correct.
|
4
|
-
|
52
|
+
Uri.parse("android-app://tk.surume.android.misqforandroid/http/host/path")
|
53
|
+
);
|
54
|
+
AppIndex.AppIndexApi.start(client, viewAction);
|
55
|
+
}
|
56
|
+
|
57
|
+
@Override
|
58
|
+
public void onStop() {
|
59
|
+
super.onStop();
|
60
|
+
|
61
|
+
// ATTENTION: This was auto-generated to implement the App Indexing API.
|
62
|
+
// See https://g.co/AppIndexing/AndroidStudio for more information.
|
63
|
+
Action viewAction = Action.newAction(
|
64
|
+
Action.TYPE_VIEW, // TODO: choose an action type.
|
65
|
+
"Login Page", // TODO: Define a title for the content shown.
|
66
|
+
// TODO: If you have web page content that matches this app activity's content,
|
67
|
+
// make sure this auto-generated web page URL is correct.
|
68
|
+
// Otherwise, set the URL to null.
|
69
|
+
Uri.parse("http://host/path"),
|
70
|
+
// TODO: Make sure this auto-generated app URL is correct.
|
71
|
+
Uri.parse("android-app://tk.surume.android.misqforandroid/http/host/path")
|
72
|
+
);
|
73
|
+
AppIndex.AppIndexApi.end(client, viewAction);
|
74
|
+
client.disconnect();
|
75
|
+
}
|
76
|
+
|
77
|
+
public void onLoginClicked(View v){
|
78
|
+
EditText screenNameInput = (EditText)findViewById(R.id.screenName);
|
79
|
+
System.out.println(screenNameInput);
|
80
|
+
String screenName = screenNameInput.getText().toString();
|
81
|
+
Toast.makeText(this, screenName, Toast.LENGTH_LONG).show();
|
82
|
+
}
|
83
|
+
}
|
84
|
+
```
|
85
|
+
|
86
|
+
```xml
|
87
|
+
<?xml version="1.0" encoding="utf-8"?>
|
88
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
89
|
+
xmlns:tools="http://schemas.android.com/tools"
|
90
|
+
android:layout_width="match_parent"
|
91
|
+
android:layout_height="match_parent"
|
92
|
+
android:paddingBottom="@dimen/activity_vertical_margin"
|
93
|
+
android:paddingLeft="@dimen/activity_horizontal_margin"
|
94
|
+
android:paddingRight="@dimen/activity_horizontal_margin"
|
95
|
+
android:paddingTop="@dimen/activity_vertical_margin"
|
96
|
+
tools:context="tk.surume.android.misqforandroid.LoginActivity">
|
97
|
+
|
98
|
+
<EditText
|
99
|
+
android:layout_width="wrap_content"
|
100
|
+
android:layout_height="wrap_content"
|
101
|
+
android:id="@+id/screenName"
|
102
|
+
android:layout_alignParentTop="true"
|
103
|
+
android:layout_alignParentStart="true"
|
104
|
+
android:layout_alignParentEnd="true"
|
105
|
+
android:text="*****"
|
106
|
+
android:hint="@string/screen_name" />
|
107
|
+
|
108
|
+
<EditText
|
109
|
+
android:layout_width="wrap_content"
|
110
|
+
android:layout_height="wrap_content"
|
111
|
+
android:inputType="textPassword"
|
112
|
+
android:ems="10"
|
113
|
+
android:id="@+id/password"
|
114
|
+
android:layout_below="@+id/screenName"
|
115
|
+
android:layout_alignParentStart="true"
|
116
|
+
android:layout_alignEnd="@+id/screenName"
|
117
|
+
android:hint="@string/password"
|
118
|
+
android:text="*****" />
|
119
|
+
|
120
|
+
<Button
|
121
|
+
android:layout_width="wrap_content"
|
122
|
+
android:layout_height="wrap_content"
|
123
|
+
android:text="@string/login"
|
124
|
+
android:id="@+id/button"
|
125
|
+
android:layout_below="@+id/password"
|
126
|
+
android:layout_alignEnd="@+id/password"
|
127
|
+
android:layout_alignParentStart="true"
|
128
|
+
android:onClick="onLoginClicked" />
|
129
|
+
</RelativeLayout>
|
130
|
+
```
|
1
途中から抜けてたので修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
Androidのアプリ開発を始めました。
|
2
|
-
EditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすれば目
|
2
|
+
EditTextに入力された内容を取得したいのですが、EditTextを取得するためのfindViewByIdでnullを返してきて動きません。どうすればfindViewByIdでnullではなく目当てのEditTextを取得できるでしょうか?
|
3
3
|
|
4
4
|
ソースコード(長くなるのでGistに記述します): [https://gist.github.com/Petitsurume/041425d33471c5e3196ab92f7de57895](https://gist.github.com/Petitsurume/041425d33471c5e3196ab92f7de57895)
|