質問編集履歴
3
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -146,7 +146,7 @@
|
|
146
146
|
Edit画面で入力し、ボタンを押すと、デフォルトの表示になってしまうのですがなぜでしょうか。。。
|
147
147
|
|
148
148
|
ボタンをタップするまではエラーなく動作していますが、記述は合ってますでしょうか?
|
149
|
-
(startActivityForResult,
|
149
|
+
(startActivityForResult, onActivityResultあたりが合ってるか不安です)
|
150
150
|
|
151
151
|

|
152
152
|

|
2
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,64 +1,22 @@
|
|
1
|
-
|
1
|
+
こちらを参考にしました。
|
2
|
-
|
2
|
+
[http://yan-note.blogspot.jp/2010/09/android_4530.html
|
3
|
+
](http://yan-note.blogspot.jp/2010/09/android_4530.html)
|
3
4
|
|
4
|
-
putExtraを使うのでしょうか?
|
5
|
-
それとも別の方法?
|
6
|
-
|
7
|
-
|
8
|
-
NameJobEditActivity.java
|
9
|
-
```ここに言語を入力
|
10
|
-
public class NameJobEditActivity extends AppCompatActivity{
|
11
|
-
|
12
|
-
EditText editName;
|
13
|
-
EditText editJob;
|
14
|
-
Button button;
|
15
|
-
SubActivity subActivity;
|
16
|
-
String editedName;
|
17
|
-
String editedJob;
|
18
|
-
Intent njIntent;
|
19
|
-
String subName;
|
20
|
-
String subJob;
|
21
|
-
|
22
|
-
@Override
|
23
|
-
public void onCreate(Bundle savedInstanceState) {
|
24
|
-
super.onCreate(savedInstanceState);
|
25
|
-
setContentView(R.layout.name_job_edit);
|
26
|
-
|
27
|
-
editName = (EditText) findViewById(R.id.editName);
|
28
|
-
editJob = (EditText) findViewById(R.id.editJob);
|
29
|
-
button = (Button) findViewById(R.id.button);
|
30
|
-
|
31
|
-
|
32
|
-
editedName = editName.getText().toString();
|
33
|
-
editedJob = editJob.getText().toString();
|
34
|
-
|
35
|
-
njIntent = getIntent();
|
36
|
-
subName = njIntent.getStringExtra("LIST_NAMES");
|
37
|
-
subJob =njIntent.getStringExtra("LIST_JOBS");
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
button.setOnClickListener(new View.OnClickListener() {
|
42
|
-
@Override
|
43
|
-
public void onClick(View v) {
|
44
|
-
subActivity.text.setText(editedName);
|
45
|
-
subActivity.text2.setText(editedJob);
|
46
|
-
|
47
|
-
|
48
|
-
// ToDo ページを閉じる
|
49
|
-
|
50
|
-
}
|
51
|
-
});
|
52
|
-
```
|
53
5
|
Sub
|
54
6
|
```ここに言語を入力
|
55
7
|
public class SubActivity extends AppCompatActivity{
|
56
8
|
|
57
|
-
String name;
|
9
|
+
public String name;
|
58
|
-
String job;
|
10
|
+
public String job;
|
11
|
+
public int image;
|
12
|
+
public String comment;
|
59
13
|
public TextView text;
|
60
14
|
public TextView text2;
|
15
|
+
private static final int SUBACTIVITY = 1;
|
61
16
|
|
17
|
+
|
18
|
+
|
19
|
+
|
62
20
|
@Override
|
63
21
|
public void onCreate(Bundle savedInstanceState) {
|
64
22
|
super.onCreate(savedInstanceState);
|
@@ -78,14 +36,10 @@
|
|
78
36
|
|
79
37
|
name = sub.getStringExtra("list_names");
|
80
38
|
job = sub.getStringExtra("list_jobs");
|
81
|
-
|
39
|
+
image = sub.getIntExtra("list_images", R.drawable.human);
|
82
|
-
|
40
|
+
comment = sub.getStringExtra("list_comments");
|
83
41
|
|
84
42
|
|
85
|
-
assert text != null;
|
86
|
-
assert text2 != null;
|
87
|
-
assert imageView != null;
|
88
|
-
assert text3 != null;
|
89
43
|
text.setText(name);
|
90
44
|
text2.setText(job);
|
91
45
|
imageView.setImageResource(image);
|
@@ -95,74 +49,104 @@
|
|
95
49
|
text.setOnClickListener(new View.OnClickListener() {
|
96
50
|
@Override
|
97
51
|
public void onClick(View v) {
|
52
|
+
|
98
|
-
|
53
|
+
Intent njIntent = new Intent();
|
99
|
-
|
54
|
+
njIntent.putExtra("LIST_NAMES",name);
|
100
|
-
|
55
|
+
njIntent.putExtra("LIST_JOBS",job);
|
56
|
+
njIntent.putExtra("LIST_IMAGE",image);
|
57
|
+
njIntent.putExtra("LIST_COMMENT",comment);
|
58
|
+
|
101
59
|
njIntent.setClassName("com.example.tsuyoshiokaprofile", "com.example.tsuyoshiokaprofile.NameJobEditActivity");
|
102
60
|
startActivity(njIntent);
|
103
61
|
|
104
62
|
|
105
63
|
}
|
106
64
|
});
|
107
|
-
```
|
108
|
-
Subの
|
109
|
-
> text.setText(name);
|
110
|
-
> text2.setText(job);
|
111
65
|
|
112
|
-
|
66
|
+
ーーーーーーー中略ーーーー
|
67
|
+
@Override
|
68
|
+
protected void onActivityResult (int requestCode, int resultCode, Intent intent) {
|
69
|
+
super.onActivityResult(requestCode, resultCode, intent);
|
70
|
+
if (requestCode == SUBACTIVITY) {
|
71
|
+
if (resultCode == RESULT_OK) {
|
113
72
|
|
73
|
+
text = (TextView) findViewById(R.id.textView);
|
74
|
+
text2 = (TextView) findViewById(R.id.textView2);
|
114
|
-
|
75
|
+
Intent njIntent = getIntent();
|
115
|
-
|
76
|
+
Bundle extras = intent.getExtras();
|
77
|
+
String editedName = njIntent.getStringExtra("NAME_INPUT");
|
78
|
+
String editedJob = njIntent.getStringExtra("JOB_INPUT");
|
116
|
-
setText
|
79
|
+
text.setText(editedName);
|
80
|
+
text2.setText(editedJob);
|
81
|
+
Log.d("LogCat", "Log message");
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
117
85
|
|
86
|
+
```
|
87
|
+
NameJobEditActivity
|
118
88
|
```ここに言語を入力
|
89
|
+
package com.example.tsuyoshiokaprofile;
|
90
|
+
ーーーーーーーーーー略ーーーー
|
119
91
|
|
120
|
-
public class
|
92
|
+
public class NameJobEditActivity extends AppCompatActivity{
|
121
93
|
|
94
|
+
EditText editName;
|
95
|
+
EditText editJob;
|
96
|
+
Button button;
|
97
|
+
String editedName;
|
98
|
+
String editedJob;
|
99
|
+
Intent njIntent;
|
100
|
+
String subName;
|
101
|
+
String subJob;
|
102
|
+
private static final int SUBACTIVITY = 1;
|
122
103
|
|
104
|
+
String subText;
|
123
|
-
|
105
|
+
String subText2;
|
106
|
+
int subImage;
|
124
|
-
|
107
|
+
String subComment;
|
125
108
|
|
126
|
-
protected void onCreate(Bundle savedInstanceState) {
|
127
|
-
super.onCreate(savedInstanceState);
|
128
|
-
setContentView(R.layout.activity_main);
|
129
109
|
|
130
110
|
|
111
|
+
@Override
|
112
|
+
public void onCreate(Bundle savedInstanceState) {
|
113
|
+
super.onCreate(savedInstanceState);
|
114
|
+
setContentView(R.layout.name_job_edit);
|
131
115
|
|
132
|
-
|
116
|
+
editName = (EditText) findViewById(R.id.editName);
|
117
|
+
editJob = (EditText) findViewById(R.id.editJob);
|
118
|
+
button = (Button) findViewById(R.id.button);
|
133
119
|
|
134
|
-
//アレイリストのインスタンスを作成
|
135
|
-
memberProfilesList = new ArrayList<>();
|
136
|
-
memberProfilesList.add(new MemberProfile(getString(R.string.name1),getString(R.string.job1),R.drawable.human,getString(R.string.comment1)));
|
137
|
-
memberProfilesList.add(new MemberProfile(getString(R.string.name2),getString(R.string.job2),R.drawable.human1,getString(R.string.comment2)));
|
138
|
-
|
139
|
-
ーーー中略ーーー
|
140
|
-
```
|
141
120
|
|
142
|
-
Mainの、
|
143
|
-
> memberProfilesList.add(new MemberProfile(getString(R.string.name1),getString(R.string.job1),R.drawable.human,getString(R.string.comment1)));
|
144
121
|
|
122
|
+
button.setOnClickListener(new View.OnClickListener() {
|
123
|
+
@Override
|
145
|
-
|
124
|
+
public void onClick(View v) {
|
125
|
+
//Inputされたのを取得
|
126
|
+
editedName = editName.getText().toString();
|
127
|
+
editedJob = editJob.getText().toString();
|
128
|
+
//保存を押すと、subに戻る。
|
129
|
+
Intent intent = new Intent();
|
130
|
+
intent.setClassName("com.example.tsuyoshiokaprofile", "com.example.tsuyoshiokaprofile.SubActivity");
|
131
|
+
//intentに入力された文字列を詰める
|
132
|
+
intent.putExtra("NAME_INPUT",editedName);
|
133
|
+
intent.putExtra("JOB_INPUT",editedJob);
|
146
134
|
|
147
|
-
|
135
|
+
//値を詰めたものをSubに渡して画面遷移する
|
148
|
-
|
136
|
+
startActivityForResult(intent, SUBACTIVITY);
|
149
|
-
setTextしたい。
|
150
137
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
at android.os.Handler.handleCallback(Handler.java:739)
|
159
|
-
at android.os.Handler.dispatchMessage(Handler.java:95)
|
160
|
-
at android.os.Looper.loop(Looper.java:135)
|
161
|
-
at android.app.ActivityThread.main(ActivityThread.java:5289)
|
162
|
-
at java.lang.reflect.Method.invoke(Native Method)
|
163
|
-
at java.lang.reflect.Method.invoke(Method.java:372)
|
164
|
-
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
|
165
|
-
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
|
138
|
+
|
139
|
+
}
|
140
|
+
});
|
141
|
+
|
142
|
+
}
|
143
|
+
|
144
|
+
}
|
166
145
|
```
|
167
|
-
Subのテキストがnull?を意味している?
|
168
|
-
で
|
146
|
+
Edit画面で入力し、ボタンを押すと、デフォルトの表示になってしまうのですがなぜでしょうか。。。
|
147
|
+
|
148
|
+
ボタンをタップするまではエラーなく動作していますが、記述は合ってますでしょうか?
|
149
|
+
(startActivityForResult, getActivityResultあたりが合ってるか不安です)
|
150
|
+
|
151
|
+

|
152
|
+

|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,8 +12,13 @@
|
|
12
12
|
EditText editName;
|
13
13
|
EditText editJob;
|
14
14
|
Button button;
|
15
|
+
SubActivity subActivity;
|
16
|
+
String editedName;
|
17
|
+
String editedJob;
|
18
|
+
Intent njIntent;
|
19
|
+
String subName;
|
20
|
+
String subJob;
|
15
21
|
|
16
|
-
|
17
22
|
@Override
|
18
23
|
public void onCreate(Bundle savedInstanceState) {
|
19
24
|
super.onCreate(savedInstanceState);
|
@@ -24,43 +29,55 @@
|
|
24
29
|
button = (Button) findViewById(R.id.button);
|
25
30
|
|
26
31
|
|
32
|
+
editedName = editName.getText().toString();
|
33
|
+
editedJob = editJob.getText().toString();
|
27
34
|
|
35
|
+
njIntent = getIntent();
|
36
|
+
subName = njIntent.getStringExtra("LIST_NAMES");
|
37
|
+
subJob =njIntent.getStringExtra("LIST_JOBS");
|
28
38
|
|
29
|
-
button.setOnClickListener(new View.OnClickListener() {
|
30
|
-
@Override
|
31
|
-
public void onClick(View v) {
|
32
39
|
|
33
|
-
// .setText(editName);
|
34
|
-
// .setText(editJob);
|
35
40
|
|
41
|
+
button.setOnClickListener(new View.OnClickListener() {
|
42
|
+
@Override
|
43
|
+
public void onClick(View v) {
|
44
|
+
subActivity.text.setText(editedName);
|
45
|
+
subActivity.text2.setText(editedJob);
|
46
|
+
|
47
|
+
|
36
48
|
// ToDo ページを閉じる
|
37
49
|
|
38
50
|
}
|
39
51
|
});
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
}
|
44
52
|
```
|
45
53
|
Sub
|
46
54
|
```ここに言語を入力
|
47
55
|
public class SubActivity extends AppCompatActivity{
|
56
|
+
|
57
|
+
String name;
|
58
|
+
String job;
|
59
|
+
public TextView text;
|
60
|
+
public TextView text2;
|
61
|
+
|
48
62
|
@Override
|
49
63
|
public void onCreate(Bundle savedInstanceState) {
|
50
64
|
super.onCreate(savedInstanceState);
|
51
65
|
setContentView(R.layout.sub_activity);
|
52
66
|
|
67
|
+
android.support.v7.app.ActionBar actionbar = getSupportActionBar();
|
53
|
-
|
68
|
+
actionbar.setHomeButtonEnabled(true);
|
69
|
+
actionbar.setDisplayHomeAsUpEnabled(true);
|
54
70
|
|
55
|
-
|
71
|
+
text = (TextView) findViewById(R.id.textView);
|
56
|
-
|
72
|
+
text2 = (TextView) findViewById(R.id.textView2);
|
57
73
|
TextView text3 = (TextView) findViewById(R.id.textView3);
|
58
74
|
ImageView imageView = (ImageView) findViewById(R.id.imageView);
|
75
|
+
ListView listView = (ListView)findViewById(R.id.listView1);
|
59
76
|
|
60
77
|
Intent sub = getIntent();
|
61
78
|
|
62
|
-
|
79
|
+
name = sub.getStringExtra("list_names");
|
63
|
-
|
80
|
+
job = sub.getStringExtra("list_jobs");
|
64
81
|
int image = sub.getIntExtra("list_images", R.drawable.human);
|
65
82
|
String comment = sub.getStringExtra("list_comments");
|
66
83
|
|
@@ -74,7 +91,19 @@
|
|
74
91
|
imageView.setImageResource(image);
|
75
92
|
text3.setText(comment);
|
76
93
|
|
94
|
+
|
95
|
+
text.setOnClickListener(new View.OnClickListener() {
|
77
|
-
|
96
|
+
@Override
|
97
|
+
public void onClick(View v) {
|
98
|
+
Intent njIntent = new Intent();
|
99
|
+
njIntent.putExtra("LIST_NAMES",name);
|
100
|
+
njIntent.putExtra("LIST_JOBS",job);
|
101
|
+
njIntent.setClassName("com.example.tsuyoshiokaprofile", "com.example.tsuyoshiokaprofile.NameJobEditActivity");
|
102
|
+
startActivity(njIntent);
|
103
|
+
|
104
|
+
|
105
|
+
}
|
106
|
+
});
|
78
107
|
```
|
79
108
|
Subの
|
80
109
|
> text.setText(name);
|
@@ -117,4 +146,23 @@
|
|
117
146
|
|
118
147
|
editNameに入力されたものと、
|
119
148
|
editJobに入力されたものを
|
120
|
-
setTextしたい。
|
149
|
+
setTextしたい。
|
150
|
+
|
151
|
+
エラー
|
152
|
+
```ここに言語を入力
|
153
|
+
Process: com.example.tsuyoshiokaprofile, PID: 2204
|
154
|
+
java.lang.NullPointerException: Attempt to read from field 'android.widget.TextView com.example.tsuyoshiokaprofile.SubActivity.text' on a null object reference
|
155
|
+
at com.example.tsuyoshiokaprofile.NameJobEditActivity$1.onClick(NameJobEditActivity.java:45)
|
156
|
+
at android.view.View.performClick(View.java:4776)
|
157
|
+
at android.view.View$PerformClick.run(View.java:19793)
|
158
|
+
at android.os.Handler.handleCallback(Handler.java:739)
|
159
|
+
at android.os.Handler.dispatchMessage(Handler.java:95)
|
160
|
+
at android.os.Looper.loop(Looper.java:135)
|
161
|
+
at android.app.ActivityThread.main(ActivityThread.java:5289)
|
162
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
163
|
+
at java.lang.reflect.Method.invoke(Method.java:372)
|
164
|
+
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
|
165
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
|
166
|
+
```
|
167
|
+
Subのテキストがnull?を意味している?
|
168
|
+
でも、NameJobActivityを追加する前、Sub単体では問題なく動作していました。
|