質問編集履歴
5
ShopFragmentの85~87行目を編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,12 +78,16 @@
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
+
import android.app.Application;
|
82
|
+
|
81
83
|
import android.os.Bundle;
|
82
84
|
|
83
85
|
|
84
86
|
|
85
87
|
import androidx.fragment.app.Fragment;
|
86
88
|
|
89
|
+
import androidx.lifecycle.ViewModelProvider;
|
90
|
+
|
87
91
|
|
88
92
|
|
89
93
|
import android.util.Log;
|
@@ -238,6 +242,12 @@
|
|
238
242
|
|
239
243
|
String storeName = enterStoreNameForQuery.getText().toString();
|
240
244
|
|
245
|
+
budgetTrackerViewModel = new ViewModelProvider.AndroidViewModelFactory(ShopFragment.this
|
246
|
+
|
247
|
+
.getApplication())
|
248
|
+
|
249
|
+
.create(BudgetTrackerViewModel.class);
|
250
|
+
|
241
251
|
budgetTracker = new BudgetTracker();
|
242
252
|
|
243
253
|
budgetTracker.setStoreName(storeName);
|
4
元に戻しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -244,7 +244,7 @@
|
|
244
244
|
|
245
245
|
|
246
246
|
|
247
|
-
budgetTrackerViewModel.getStoreNameLists(
|
247
|
+
budgetTrackerViewModel.getStoreNameLists(storeName);
|
248
248
|
|
249
249
|
|
250
250
|
|
@@ -332,12 +332,14 @@
|
|
332
332
|
|
333
333
|
|
334
334
|
|
335
|
-
public List<BudgetTracker> getStoreNameLists(
|
335
|
+
public List<BudgetTracker> getStoreNameLists(String storeName) {
|
336
|
-
|
336
|
+
|
337
|
-
storeNameLists = repository.queryStoreName(
|
337
|
+
storeNameLists = repository.queryStoreName(storeName);
|
338
338
|
|
339
339
|
return storeNameLists;
|
340
340
|
|
341
|
+
}
|
342
|
+
|
341
343
|
|
342
344
|
|
343
345
|
public static void insert(BudgetTracker budgetTracker) {
|
@@ -350,6 +352,4 @@
|
|
350
352
|
|
351
353
|
|
352
354
|
|
353
|
-
|
354
|
-
|
355
355
|
```
|
3
BudgetTRackerViewModelのgetStoreNameListsのgetStoreNameListsメソッドを変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -332,14 +332,12 @@
|
|
332
332
|
|
333
333
|
|
334
334
|
|
335
|
-
public List<BudgetTracker> getStoreNameLists(
|
335
|
+
public List<BudgetTracker> getStoreNameLists(BudgetTracker budgetTracker) {
|
336
|
-
|
336
|
+
|
337
|
-
storeNameLists = repository.queryStoreName(
|
337
|
+
storeNameLists = repository.queryStoreName(budgetTracker.getStoreName());
|
338
338
|
|
339
339
|
return storeNameLists;
|
340
340
|
|
341
|
-
}
|
342
|
-
|
343
341
|
|
344
342
|
|
345
343
|
public static void insert(BudgetTracker budgetTracker) {
|
2
エラー内容を更新しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,13 +32,13 @@
|
|
32
32
|
|
33
33
|
```ここに言語を入力
|
34
34
|
|
35
|
-
2021-12-1
|
35
|
+
2021-12-16 16:39:45.420 30171-30171/? E/AndroidRuntime: FATAL EXCEPTION: main
|
36
|
-
|
36
|
+
|
37
|
-
Process: com.myproject.offlinebudgettrackerappproject, PID: 1
|
37
|
+
Process: com.myproject.offlinebudgettrackerappproject, PID: 30171
|
38
38
|
|
39
39
|
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.myproject.offlinebudgettrackerappproject.model.BudgetTrackerViewModel.getStoreNameLists(java.lang.String)' on a null object reference
|
40
40
|
|
41
|
-
at com.myproject.offlinebudgettrackerappproject.ShopFragment$1.onClick(ShopFragment.java:8
|
41
|
+
at com.myproject.offlinebudgettrackerappproject.ShopFragment$1.onClick(ShopFragment.java:86)
|
42
42
|
|
43
43
|
at android.view.View.performClick(View.java:7259)
|
44
44
|
|
@@ -64,6 +64,8 @@
|
|
64
64
|
|
65
65
|
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
|
66
66
|
|
67
|
+
|
68
|
+
|
67
69
|
```
|
68
70
|
|
69
71
|
|
@@ -104,6 +106,10 @@
|
|
104
106
|
|
105
107
|
|
106
108
|
|
109
|
+
import java.util.List;
|
110
|
+
|
111
|
+
|
112
|
+
|
107
113
|
/**
|
108
114
|
|
109
115
|
* A simple {@link Fragment} subclass.
|
@@ -226,18 +232,26 @@
|
|
226
232
|
|
227
233
|
public void onClick(View view) {
|
228
234
|
|
235
|
+
BudgetTracker budgetTracker;
|
236
|
+
|
229
237
|
|
230
238
|
|
231
239
|
String storeName = enterStoreNameForQuery.getText().toString();
|
232
240
|
|
233
|
-
|
241
|
+
budgetTracker = new BudgetTracker();
|
242
|
+
|
234
|
-
|
243
|
+
budgetTracker.setStoreName(storeName);
|
244
|
+
|
245
|
+
|
246
|
+
|
235
|
-
budgetTrackerViewModel.getStoreNameLists(
|
247
|
+
budgetTrackerViewModel.getStoreNameLists(budgetTracker.getStoreName());
|
236
248
|
|
237
249
|
|
238
250
|
|
239
251
|
Log.d("TAG", "onClick: " + enterStoreNameForQuery.getText().toString());
|
240
252
|
|
253
|
+
// Log.d("TAG", "onClick: " + list);
|
254
|
+
|
241
255
|
|
242
256
|
|
243
257
|
}
|
@@ -262,35 +276,23 @@
|
|
262
276
|
|
263
277
|
```ここに言語を入力
|
264
278
|
|
265
|
-
package com.myproject.offlinebudgettrackerappproject;
|
279
|
+
package com.myproject.offlinebudgettrackerappproject.model;
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
280
|
+
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
281
|
+
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
282
|
+
|
278
|
-
|
279
|
-
import android.view.LayoutInflater;
|
280
|
-
|
281
|
-
import android.view.View;
|
282
|
-
|
283
|
-
import android.view.ViewGroup;
|
284
|
-
|
285
|
-
import android.
|
283
|
+
import android.app.Application;
|
284
|
+
|
285
|
+
|
286
|
+
|
286
|
-
|
287
|
+
import androidx.annotation.NonNull;
|
288
|
+
|
289
|
+
import androidx.lifecycle.AndroidViewModel;
|
290
|
+
|
287
|
-
import android.
|
291
|
+
import androidx.lifecycle.LiveData;
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
+
|
292
|
-
|
293
|
+
|
294
|
+
|
293
|
-
import com.myproject.offlinebudgettrackerappproject.
|
295
|
+
import com.myproject.offlinebudgettrackerappproject.data.BudgetTrackerRepository;
|
294
296
|
|
295
297
|
|
296
298
|
|
@@ -298,164 +300,58 @@
|
|
298
300
|
|
299
301
|
|
300
302
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
p
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
p
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
* Use this factory method to create a new instance of
|
350
|
-
|
351
|
-
* this fragment using the provided parameters.
|
352
|
-
|
353
|
-
*
|
354
|
-
|
355
|
-
* @param param1 Parameter 1.
|
356
|
-
|
357
|
-
* @param param2 Parameter 2.
|
358
|
-
|
359
|
-
* @return A new instance of fragment ShopFragment.
|
360
|
-
|
361
|
-
*/
|
362
|
-
|
363
|
-
// TODO: Rename and change types and number of parameters
|
364
|
-
|
365
|
-
public static ShopFragment newInstance(String param1, String param2) {
|
366
|
-
|
367
|
-
ShopFragment fragment = new ShopFragment();
|
368
|
-
|
369
|
-
Bundle args = new Bundle();
|
370
|
-
|
371
|
-
args.putString(ARG_PARAM1, param1);
|
372
|
-
|
373
|
-
args.putString(ARG_PARAM2, param2);
|
374
|
-
|
375
|
-
fragment.setArguments(args);
|
376
|
-
|
377
|
-
return fragment;
|
378
|
-
|
379
|
-
}
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
@Override
|
384
|
-
|
385
|
-
public void onCreate(Bundle savedInstanceState) {
|
386
|
-
|
387
|
-
super.onCreate(savedInstanceState);
|
388
|
-
|
389
|
-
if (getArguments() != null) {
|
390
|
-
|
391
|
-
mParam1 = getArguments().getString(ARG_PARAM1);
|
392
|
-
|
393
|
-
mParam2 = getArguments().getString(ARG_PARAM2);
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
}
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
@Override
|
404
|
-
|
405
|
-
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
406
|
-
|
407
|
-
Bundle savedInstanceState) {
|
408
|
-
|
409
|
-
View view = inflater.inflate(R.layout.fragment_shop, container, false);
|
410
|
-
|
411
|
-
EditText enterStoreNameForQuery = (EditText) view.findViewById(R.id.shop_search);
|
412
|
-
|
413
|
-
Button storeSearchQueryBtn = (Button) view.findViewById(R.id.btn_shop_search);
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
storeSearchQueryBtn.setOnClickListener(new View.OnClickListener() {
|
418
|
-
|
419
|
-
@Override
|
420
|
-
|
421
|
-
public void onClick(View view) {
|
422
|
-
|
423
|
-
BudgetTracker budgetTracker;
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
String storeName = enterStoreNameForQuery.getText().toString();
|
428
|
-
|
429
|
-
budgetTracker = new BudgetTracker();
|
430
|
-
|
431
|
-
budgetTracker.setStoreName(storeName);
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
budgetTrackerViewModel.getStoreNameLists(budgetTracker.getStoreName());
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
Log.d("TAG", "onClick: " + enterStoreNameForQuery.getText().toString());
|
440
|
-
|
441
|
-
// Log.d("TAG", "onClick: " + list);
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
}
|
446
|
-
|
447
|
-
});
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
return view;
|
452
|
-
|
453
|
-
}
|
454
|
-
|
455
|
-
|
303
|
+
public class BudgetTrackerViewModel extends AndroidViewModel {
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
public static BudgetTrackerRepository repository;
|
308
|
+
|
309
|
+
public final LiveData<List<BudgetTracker>> allBudgetTrackerLists;
|
310
|
+
|
311
|
+
public List<BudgetTracker> storeNameLists;
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
public BudgetTrackerViewModel(@NonNull Application application) {
|
316
|
+
|
317
|
+
super(application);
|
318
|
+
|
319
|
+
repository = new BudgetTrackerRepository(application);
|
320
|
+
|
321
|
+
allBudgetTrackerLists = repository.getAllBudgetTrackerData();
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
public LiveData<List<BudgetTracker>> getAllBudgetTrackerLists() {
|
328
|
+
|
329
|
+
return allBudgetTrackerLists;
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
public List<BudgetTracker> getStoreNameLists(String storeName) {
|
336
|
+
|
337
|
+
storeNameLists = repository.queryStoreName(storeName);
|
338
|
+
|
339
|
+
return storeNameLists;
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
public static void insert(BudgetTracker budgetTracker) {
|
346
|
+
|
347
|
+
repository.insert(budgetTracker);
|
348
|
+
|
349
|
+
}
|
456
350
|
|
457
351
|
}
|
458
352
|
|
459
353
|
|
460
354
|
|
355
|
+
|
356
|
+
|
461
357
|
```
|
1
ShopFragmnetの82~84行目を更新しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -262,23 +262,35 @@
|
|
262
262
|
|
263
263
|
```ここに言語を入力
|
264
264
|
|
265
|
-
package com.myproject.offlinebudgettrackerappproject
|
265
|
+
package com.myproject.offlinebudgettrackerappproject;
|
266
|
+
|
267
|
+
|
268
|
+
|
266
|
-
|
269
|
+
import android.os.Bundle;
|
270
|
+
|
271
|
+
|
272
|
+
|
267
|
-
|
273
|
+
import androidx.fragment.app.Fragment;
|
274
|
+
|
275
|
+
|
276
|
+
|
268
|
-
|
277
|
+
import android.util.Log;
|
278
|
+
|
279
|
+
import android.view.LayoutInflater;
|
280
|
+
|
281
|
+
import android.view.View;
|
282
|
+
|
283
|
+
import android.view.ViewGroup;
|
284
|
+
|
269
|
-
import android.
|
285
|
+
import android.widget.Button;
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
286
|
+
|
274
|
-
|
275
|
-
import androidx.lifecycle.AndroidViewModel;
|
276
|
-
|
277
|
-
import android
|
287
|
+
import android.widget.EditText;
|
288
|
+
|
289
|
+
|
290
|
+
|
278
|
-
|
291
|
+
import com.myproject.offlinebudgettrackerappproject.model.BudgetTracker;
|
279
|
-
|
280
|
-
|
292
|
+
|
281
|
-
import com.myproject.offlinebudgettrackerappproject.d
|
293
|
+
import com.myproject.offlinebudgettrackerappproject.model.BudgetTrackerViewModel;
|
282
294
|
|
283
295
|
|
284
296
|
|
@@ -286,53 +298,161 @@
|
|
286
298
|
|
287
299
|
|
288
300
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
p
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
p
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
301
|
+
/**
|
302
|
+
|
303
|
+
* A simple {@link Fragment} subclass.
|
304
|
+
|
305
|
+
* Use the {@link ShopFragment#newInstance} factory method to
|
306
|
+
|
307
|
+
* create an instance of this fragment.
|
308
|
+
|
309
|
+
*/
|
310
|
+
|
311
|
+
public class ShopFragment extends Fragment {
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
BudgetTrackerViewModel budgetTrackerViewModel;
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
// TODO: Rename parameter arguments, choose names that match
|
322
|
+
|
323
|
+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
324
|
+
|
325
|
+
private static final String ARG_PARAM1 = "param1";
|
326
|
+
|
327
|
+
private static final String ARG_PARAM2 = "param2";
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
// TODO: Rename and change types of parameters
|
332
|
+
|
333
|
+
private String mParam1;
|
334
|
+
|
335
|
+
private String mParam2;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
public ShopFragment() {
|
340
|
+
|
341
|
+
// Required empty public constructor
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
/**
|
348
|
+
|
349
|
+
* Use this factory method to create a new instance of
|
350
|
+
|
351
|
+
* this fragment using the provided parameters.
|
352
|
+
|
353
|
+
*
|
354
|
+
|
355
|
+
* @param param1 Parameter 1.
|
356
|
+
|
357
|
+
* @param param2 Parameter 2.
|
358
|
+
|
359
|
+
* @return A new instance of fragment ShopFragment.
|
360
|
+
|
361
|
+
*/
|
362
|
+
|
363
|
+
// TODO: Rename and change types and number of parameters
|
364
|
+
|
365
|
+
public static ShopFragment newInstance(String param1, String param2) {
|
366
|
+
|
367
|
+
ShopFragment fragment = new ShopFragment();
|
368
|
+
|
369
|
+
Bundle args = new Bundle();
|
370
|
+
|
371
|
+
args.putString(ARG_PARAM1, param1);
|
372
|
+
|
373
|
+
args.putString(ARG_PARAM2, param2);
|
374
|
+
|
375
|
+
fragment.setArguments(args);
|
376
|
+
|
377
|
+
return fragment;
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
@Override
|
384
|
+
|
385
|
+
public void onCreate(Bundle savedInstanceState) {
|
386
|
+
|
387
|
+
super.onCreate(savedInstanceState);
|
388
|
+
|
389
|
+
if (getArguments() != null) {
|
390
|
+
|
391
|
+
mParam1 = getArguments().getString(ARG_PARAM1);
|
392
|
+
|
393
|
+
mParam2 = getArguments().getString(ARG_PARAM2);
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
@Override
|
404
|
+
|
405
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
406
|
+
|
407
|
+
Bundle savedInstanceState) {
|
408
|
+
|
409
|
+
View view = inflater.inflate(R.layout.fragment_shop, container, false);
|
410
|
+
|
411
|
+
EditText enterStoreNameForQuery = (EditText) view.findViewById(R.id.shop_search);
|
412
|
+
|
413
|
+
Button storeSearchQueryBtn = (Button) view.findViewById(R.id.btn_shop_search);
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
storeSearchQueryBtn.setOnClickListener(new View.OnClickListener() {
|
418
|
+
|
419
|
+
@Override
|
420
|
+
|
421
|
+
public void onClick(View view) {
|
422
|
+
|
423
|
+
BudgetTracker budgetTracker;
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
String storeName = enterStoreNameForQuery.getText().toString();
|
428
|
+
|
429
|
+
budgetTracker = new BudgetTracker();
|
430
|
+
|
431
|
+
budgetTracker.setStoreName(storeName);
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
budgetTrackerViewModel.getStoreNameLists(budgetTracker.getStoreName());
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
Log.d("TAG", "onClick: " + enterStoreNameForQuery.getText().toString());
|
440
|
+
|
441
|
+
// Log.d("TAG", "onClick: " + list);
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
});
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
return view;
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
|
336
456
|
|
337
457
|
}
|
338
458
|
|