質問編集履歴
4
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,13 +38,34 @@
|
|
38
38
|
fragment1.java
|
39
39
|
```java
|
40
40
|
|
41
|
+
public class MainFragment extends Fragment {
|
42
|
+
|
43
|
+
public static final String Gtai12 = "person_id";
|
44
|
+
//public static final String EXTRA_MODE_ID = "mode_id";
|
45
|
+
|
46
|
+
|
47
|
+
fragment2 fragment02 = new fragment2();
|
48
|
+
|
49
|
+
|
50
|
+
private MainViewModel mViewModel;
|
51
|
+
|
41
|
-
public static MainFragment newInstance() {
|
52
|
+
public static MainFragment newInstance() {
|
42
53
|
return new MainFragment();
|
43
54
|
}
|
55
|
+
|
56
|
+
@Nullable
|
44
|
-
@Override
|
57
|
+
@Override
|
58
|
+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
59
|
+
@Nullable Bundle savedInstanceState) {
|
60
|
+
return inflater.inflate(R.layout.main_fragment, container, false);
|
61
|
+
}
|
62
|
+
|
63
|
+
@Override
|
45
64
|
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
46
65
|
super.onViewCreated(view, savedInstanceState);
|
47
66
|
|
67
|
+
|
68
|
+
|
48
69
|
Bundle args = getArguments();
|
49
70
|
|
50
71
|
Button button01 = view.findViewById(R.id.button);
|
@@ -66,23 +87,44 @@
|
|
66
87
|
}
|
67
88
|
}
|
68
89
|
});
|
69
|
-
}
|
90
|
+
}
|
70
91
|
|
71
|
-
|
92
|
+
@Override
|
72
93
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
73
94
|
super.onActivityCreated(savedInstanceState);
|
74
95
|
mViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
|
75
96
|
// TODO: Use the ViewModel
|
76
97
|
}
|
77
98
|
|
99
|
+
}
|
100
|
+
|
78
101
|
```
|
79
102
|
|
80
103
|
fragment2.java
|
81
104
|
|
82
105
|
```java
|
106
|
+
|
83
107
|
public class fragment2 extends Fragment {
|
84
108
|
|
109
|
+
private int cnt = 0;
|
85
110
|
|
111
|
+
private String gtai;
|
112
|
+
//入力されたやつを数値に変えた体重
|
113
|
+
private double tai;
|
114
|
+
private double bmi;
|
115
|
+
|
116
|
+
private String s;
|
117
|
+
|
118
|
+
double shin = 150.2;
|
119
|
+
//double tai = 50.8;
|
120
|
+
double mtai = 58.0;
|
121
|
+
|
122
|
+
Calendar cal = Calendar.getInstance();
|
123
|
+
int month = cal.get(Calendar.MONTH) + 1;
|
124
|
+
|
125
|
+
double shinm = shin / 100;
|
126
|
+
double shinm2 = shinm * shinm;
|
127
|
+
|
86
128
|
public static fragment2 newInstance(int count) {
|
87
129
|
// Fragemnt02 インスタンス生成
|
88
130
|
fragment2 fragment02 = new fragment2();
|
@@ -95,12 +137,12 @@
|
|
95
137
|
return fragment02;
|
96
138
|
}
|
97
139
|
|
98
|
-
// FragmentのViewを生成して返す
|
140
|
+
// FragmentのViewを生成して返す
|
99
141
|
@Override
|
100
142
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
101
143
|
ViewGroup container,
|
102
|
-
Bundle savedInstanceState){
|
144
|
+
Bundle savedInstanceState) {
|
103
|
-
View wf = inflater.inflate(R.layout.fragment, container, false);
|
145
|
+
View wf = inflater.inflate(R.layout.fragment, container, false);
|
104
146
|
|
105
147
|
// 画面回転時にFragmentの再生成を禁止
|
106
148
|
setRetainInstance(true);
|
@@ -111,21 +153,72 @@
|
|
111
153
|
return wf;
|
112
154
|
}
|
113
155
|
|
114
|
-
@Override
|
156
|
+
@Override
|
115
157
|
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
116
158
|
super.onViewCreated(view, savedInstanceState);
|
117
159
|
|
118
160
|
final TextView reserve_2c_text = getActivity().findViewById(R.id.textView);
|
161
|
+
// R.id.textviewはフラグメント1内の書き込みたいセルのid
|
119
|
-
|
162
|
+
//fragment.xml には textview はつけてない
|
120
163
|
|
164
|
+
Bundle args = getArguments();
|
165
|
+
|
166
|
+
/*@Override
|
167
|
+
public void onStart() {
|
168
|
+
super.onStart();*/
|
121
|
-
|
169
|
+
Button bu1 = (Button) getActivity().findViewById(R.id.button2);
|
170
|
+
|
122
171
|
bu1.setOnClickListener(new View.OnClickListener(){
|
172
|
+
@Override
|
173
|
+
public void onClick(View view){
|
123
|
-
|
174
|
+
EditText ked = (EditText) getActivity().findViewById(R.id.editText);
|
124
|
-
@Override
|
125
|
-
|
175
|
+
EditText mted = (EditText) getActivity().findViewById(R.id.editText2);
|
176
|
+
EditText ted = (EditText) getActivity().findViewById(R.id.editText3);
|
126
177
|
|
178
|
+
//今は月単位の指定しかできない
|
179
|
+
//入力値を文字列から数値へ 数値から文字列へして表示
|
180
|
+
String kikan = ked.getText().toString();
|
181
|
+
String mtai = mted.getText().toString();
|
127
|
-
|
182
|
+
gtai = ted.getText().toString();
|
183
|
+
Toast.makeText(getActivity(), "click", Toast.LENGTH_SHORT).show();
|
184
|
+
if (kikan.length() != 0) {
|
185
|
+
int i = Integer.parseInt(kikan);
|
186
|
+
int mki = month + i;
|
187
|
+
if (mki > 12) {
|
188
|
+
mki -= 12;
|
189
|
+
}
|
190
|
+
s = String.valueOf(mki);
|
191
|
+
ked.getEditableText().clear();
|
192
|
+
}else{
|
128
193
|
|
194
|
+
}
|
195
|
+
|
196
|
+
if (mtai.length() != 0) {
|
197
|
+
mted.getEditableText().clear();
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
if(gtai.length() != 0){
|
202
|
+
tai = Double.parseDouble(gtai);
|
203
|
+
bmi = tai / shinm2;
|
204
|
+
ted.getEditableText().clear();
|
205
|
+
}
|
206
|
+
|
207
|
+
// ここでフラグメント1にあるテーブル内のセルに値を書き込んでいる
|
208
|
+
reserve_2c_text.setText("現在の体重" + gtai);
|
209
|
+
}
|
210
|
+
});
|
211
|
+
}
|
212
|
+
/*
|
213
|
+
private void showPerson(String personId) {
|
214
|
+
Intent intent = new Intent(fragment2.this,MainFragment.);
|
215
|
+
intent.putExtra(MainFragment.Gtai12, personId);
|
216
|
+
// intent.putExtra(PersonActivity.EXTRA_MODE_ID, MODE_PRIVACY);
|
217
|
+
// ^^^if needed^^^
|
218
|
+
startActivity(intent);
|
219
|
+
}*/
|
220
|
+
}
|
221
|
+
|
129
222
|
```
|
130
223
|
|
131
224
|
### 試したこと
|
3
文章の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,8 +37,13 @@
|
|
37
37
|
|
38
38
|
fragment1.java
|
39
39
|
```java
|
40
|
+
|
41
|
+
public static MainFragment newInstance() {
|
42
|
+
return new MainFragment();
|
43
|
+
}
|
40
44
|
@Override
|
41
|
-
public void onViewCreated(
|
45
|
+
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
46
|
+
super.onViewCreated(view, savedInstanceState);
|
42
47
|
|
43
48
|
Bundle args = getArguments();
|
44
49
|
|
@@ -61,7 +66,15 @@
|
|
61
66
|
}
|
62
67
|
}
|
63
68
|
});
|
69
|
+
}
|
64
70
|
|
71
|
+
@Override
|
72
|
+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
73
|
+
super.onActivityCreated(savedInstanceState);
|
74
|
+
mViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
|
75
|
+
// TODO: Use the ViewModel
|
76
|
+
}
|
77
|
+
|
65
78
|
```
|
66
79
|
|
67
80
|
fragment2.java
|
@@ -84,7 +97,10 @@
|
|
84
97
|
|
85
98
|
// FragmentのViewを生成して返す
|
86
99
|
@Override
|
87
|
-
public View onCreateView(
|
100
|
+
public View onCreateView(@NonNull LayoutInflater inflater,
|
101
|
+
ViewGroup container,
|
102
|
+
Bundle savedInstanceState){
|
103
|
+
View wf = inflater.inflate(R.layout.fragment, container, false);
|
88
104
|
|
89
105
|
// 画面回転時にFragmentの再生成を禁止
|
90
106
|
setRetainInstance(true);
|
@@ -96,7 +112,8 @@
|
|
96
112
|
}
|
97
113
|
|
98
114
|
@Override
|
99
|
-
public void onViewCreated(
|
115
|
+
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
116
|
+
super.onViewCreated(view, savedInstanceState);
|
100
117
|
|
101
118
|
final TextView reserve_2c_text = getActivity().findViewById(R.id.textView);
|
102
119
|
Bundle args = getArguments();
|
@@ -125,4 +142,5 @@
|
|
125
142
|
|
126
143
|
### 補足情報(FW/ツールのバージョンなど)
|
127
144
|
|
128
|
-
|
145
|
+
android studio Version 3.5
|
146
|
+
選んだものは Fragment + ViewModel かと思います
|
2
文章の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -35,10 +35,8 @@
|
|
35
35
|
|
36
36
|
### 該当のソースコード
|
37
37
|
|
38
|
+
fragment1.java
|
38
39
|
```java
|
39
|
-
fragment1.java
|
40
|
-
```
|
41
|
-
|
42
40
|
@Override
|
43
41
|
public void onViewCreated(~~
|
44
42
|
|
@@ -64,12 +62,11 @@
|
|
64
62
|
}
|
65
63
|
});
|
66
64
|
|
65
|
+
```
|
67
66
|
|
67
|
+
fragment2.java
|
68
68
|
|
69
69
|
```java
|
70
|
-
fragment2.java
|
71
|
-
```
|
72
|
-
|
73
70
|
public class fragment2 extends Fragment {
|
74
71
|
|
75
72
|
|
@@ -111,8 +108,9 @@
|
|
111
108
|
public void onClick(View view){
|
112
109
|
|
113
110
|
reserve_2c_text.setText("");
|
114
|
-
~~~~
|
115
111
|
|
112
|
+
```
|
113
|
+
|
116
114
|
### 試したこと
|
117
115
|
|
118
116
|
値の受け渡しにこちらにあった過去の質問の
|
1
文章の編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -35,13 +35,10 @@
|
|
35
35
|
|
36
36
|
### 該当のソースコード
|
37
37
|
|
38
|
-
```ここに言語名を入力
|
39
|
-
java
|
38
|
+
```java
|
39
|
+
fragment1.java
|
40
40
|
```
|
41
41
|
|
42
|
-
|
43
|
-
fragment1.java
|
44
|
-
|
45
42
|
@Override
|
46
43
|
public void onViewCreated(~~
|
47
44
|
|
@@ -69,7 +66,9 @@
|
|
69
66
|
|
70
67
|
|
71
68
|
|
69
|
+
```java
|
72
70
|
fragment2.java
|
71
|
+
```
|
73
72
|
|
74
73
|
public class fragment2 extends Fragment {
|
75
74
|
|