質問編集履歴
11
Currency.javaを編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,8 +14,9 @@
|
|
14
14
|
図1(通貨設定画面)
|
15
15
|

|
16
16
|
|
17
|
-
図2 (
|
17
|
+
図2 (ブレークポイント)
|
18
|
-

|
19
|
+
|
19
20
|
|
20
21
|
BudgetTrackerSettingsActivity.java
|
21
22
|
```ここに言語を入力
|
@@ -92,11 +93,15 @@
|
|
92
93
|
```ここに言語を入力
|
93
94
|
package com.myproject.offlinebudgettrackerappproject;
|
94
95
|
|
95
|
-
|
96
|
+
import java.util.ArrayList;
|
96
97
|
|
97
98
|
public class Currency {
|
98
99
|
|
99
100
|
private static ArrayList<Currency> currencyArrayList = new ArrayList<>();
|
101
|
+
|
102
|
+
static {
|
103
|
+
initCurrencies();
|
104
|
+
}
|
100
105
|
|
101
106
|
private String id;
|
102
107
|
private String currency;
|
@@ -154,6 +159,7 @@
|
|
154
159
|
return currencyArrayList;
|
155
160
|
}
|
156
161
|
}
|
162
|
+
|
157
163
|
|
158
164
|
```
|
159
165
|
|
10
図2 (cyrrencyArreylist)を編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|

|
16
16
|
|
17
17
|
図2 (cyrrencyArreylist)
|
18
|
-

|
19
19
|
|
20
20
|
BudgetTrackerSettingsActivity.java
|
21
21
|
```ここに言語を入力
|
9
図3 (cyrrencyArreylist)を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
図1(通貨設定画面)
|
15
15
|

|
16
16
|
|
17
|
-
図2
|
17
|
+
図2 (cyrrencyArreylist)
|
18
|
-

|
19
19
|
|
20
20
|
BudgetTrackerSettingsActivity.java
|
21
21
|
```ここに言語を入力
|
8
HomeFragment編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -209,6 +209,7 @@
|
|
209
209
|
//選択された通貨の設定
|
210
210
|
String currentCurrency = sharedPreferences.getString("CURRENCY", "");
|
211
211
|
int currentCurrencyNum = sharedPreferences.getInt("PREF_CURRENCY_VALUE", 0);
|
212
|
+
//126行目
|
212
213
|
Currency currency = Currency.getCurrencyArrayList().get(currentCurrencyNum);
|
213
214
|
|
214
215
|
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(currency.getCurrencyImage(), 0, 0, 0);
|
7
IndexOutOfBoundsException(エラー内容)記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -213,3 +213,37 @@
|
|
213
213
|
|
214
214
|
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(currency.getCurrencyImage(), 0, 0, 0);
|
215
215
|
```
|
216
|
+
IndexOutOfBoundsException(エラー内容)
|
217
|
+
```ここに言語を入力
|
218
|
+
2022-06-12 09:57:04.765 32399-32399/com.myproject.offlinebudgettrackerappproject E/AndroidRuntime: FATAL EXCEPTION: main
|
219
|
+
Process: com.myproject.offlinebudgettrackerappproject, PID: 32399
|
220
|
+
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
|
221
|
+
at java.util.ArrayList.get(ArrayList.java:437)
|
222
|
+
at com.myproject.offlinebudgettrackerappproject.HomeFragment.onCreateView(HomeFragment.java:126)
|
223
|
+
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
|
224
|
+
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
|
225
|
+
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
|
226
|
+
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
|
227
|
+
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
|
228
|
+
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
|
229
|
+
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
|
230
|
+
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
|
231
|
+
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
|
232
|
+
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
|
233
|
+
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
|
234
|
+
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1432)
|
235
|
+
at android.app.Activity.performStart(Activity.java:7848)
|
236
|
+
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3294)
|
237
|
+
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
|
238
|
+
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
|
239
|
+
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
|
240
|
+
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
|
241
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
|
242
|
+
at android.os.Handler.dispatchMessage(Handler.java:107)
|
243
|
+
at android.os.Looper.loop(Looper.java:214)
|
244
|
+
at android.app.ActivityThread.main(ActivityThread.java:7356)
|
245
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
246
|
+
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
|
247
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
|
248
|
+
|
249
|
+
```
|
6
HomeFragmentを編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -209,13 +209,7 @@
|
|
209
209
|
//選択された通貨の設定
|
210
210
|
String currentCurrency = sharedPreferences.getString("CURRENCY", "");
|
211
211
|
int currentCurrencyNum = sharedPreferences.getInt("PREF_CURRENCY_VALUE", 0);
|
212
|
-
|
213
|
-
curren
|
212
|
+
Currency currency = Currency.getCurrencyArrayList().get(currentCurrencyNum);
|
214
|
-
|
213
|
+
|
215
|
-
|
214
|
+
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(currency.getCurrencyImage(), 0, 0, 0);
|
216
|
-
} else if (currentCurrencyNum == 1) {
|
217
|
-
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_yen, 0, 0, 0);
|
218
|
-
} else if (currentCurrencyNum == 2) {
|
219
|
-
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_euro, 0, 0, 0);
|
220
|
-
}
|
221
|
-
```
|
215
|
+
```
|
5
BudgetTrackerSettingsActivity、HomeFragmentの編集とHome画面のスクショ追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,26 +14,28 @@
|
|
14
14
|
図1(通貨設定画面)
|
15
15
|

|
16
16
|
|
17
|
-
図2(
|
17
|
+
図2(Home画面)
|
18
|
-

|
19
19
|
|
20
20
|
BudgetTrackerSettingsActivity.java
|
21
21
|
```ここに言語を入力
|
22
22
|
package com.myproject.offlinebudgettrackerappproject;
|
23
23
|
|
24
24
|
<import箇所は省略>
|
25
|
+
|
26
|
+
import androidx.appcompat.app.AppCompatActivity;
|
27
|
+
|
28
|
+
import com.myproject.offlinebudgettrackerappproject.adapter.CurrencySpinnerAdapter;
|
25
29
|
|
26
30
|
public class BudgetTrackerSettingsActivity extends AppCompatActivity {
|
27
31
|
|
28
32
|
Spinner spinner;
|
29
33
|
public static String spinnerText;
|
30
34
|
|
31
|
-
CheckBox currencyRemember;
|
32
35
|
Button currencyBtn;
|
33
|
-
|
36
|
+
String selectedCurrency;
|
34
37
|
SharedPreferences sharedPreferences;
|
35
|
-
String
|
38
|
+
private static final String PREF_CURRENCY_FILENAME = "CURRENCY_SHARED";
|
36
|
-
boolean currencyChecked;
|
37
39
|
private static final String PREF_CURRENCY_VALUE = "currencyValue";
|
38
40
|
|
39
41
|
@Override
|
@@ -43,82 +45,36 @@
|
|
43
45
|
Currency.initCurrencies();
|
44
46
|
|
45
47
|
spinner = (Spinner) findViewById(R.id.currency_spinner);
|
46
|
-
currencyRemember = (CheckBox) findViewById(R.id.currency_check_box);
|
47
48
|
currencyBtn = (Button) findViewById(R.id.currency_btn);
|
48
49
|
|
49
50
|
CurrencySpinnerAdapter currencySpinnerAdapter = new CurrencySpinnerAdapter(this, R.layout.currency_spinner_adopter,
|
50
51
|
Currency.getCurrencyArrayList());
|
51
52
|
spinner.setAdapter(currencySpinnerAdapter);
|
52
53
|
|
53
|
-
sharedPreferences = getSharedPreferences(
|
54
|
+
sharedPreferences = getSharedPreferences(PREF_CURRENCY_FILENAME, Context.MODE_PRIVATE);
|
54
|
-
|
55
|
+
spinner.setSelection(sharedPreferences.getInt(PREF_CURRENCY_VALUE, 0));
|
55
56
|
|
56
57
|
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
57
58
|
@Override
|
58
59
|
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
|
59
60
|
Currency currency = (Currency) spinner.getSelectedItem();
|
60
61
|
spinnerText = currency.getCurrency();
|
61
|
-
if (spinnerText == "US Dollars") {
|
62
|
-
Toast.makeText(BudgetTrackerSettingsActivity.this, "US Dollars", Toast.LENGTH_SHORT).show();
|
63
|
-
|
62
|
+
currencyBtn.setOnClickListener(new View.OnClickListener() {
|
64
|
-
|
63
|
+
@Override
|
65
|
-
|
64
|
+
public void onClick(View view) {
|
66
|
-
|
65
|
+
selectedCurrency = spinnerText;
|
67
|
-
|
66
|
+
|
68
|
-
Vector<Vector<Float>> data = new Vector<Vector<Float>>();
|
69
|
-
|
70
|
-
|
67
|
+
SharedPreferences.Editor editor = sharedPreferences.edit();
|
71
|
-
|
68
|
+
editor.putString("CURRENCY", selectedCurrency);
|
72
|
-
editor.putBoolean("CHECKBOX", currencyChecked);
|
73
|
-
|
69
|
+
editor.putInt(PREF_CURRENCY_VALUE, position);
|
74
|
-
|
70
|
+
editor.commit();
|
75
|
-
|
71
|
+
Toast.makeText(BudgetTrackerSettingsActivity.this, "Currency Saved", Toast.LENGTH_SHORT).show();
|
76
|
-
|
72
|
+
|
77
|
-
|
73
|
+
Intent intent = new Intent(BudgetTrackerSettingsActivity.this, MainActivity.class);
|
78
|
-
|
74
|
+
startActivity(intent);
|
79
|
-
|
75
|
+
finish();
|
80
|
-
|
76
|
+
}
|
81
|
-
|
77
|
+
});
|
82
|
-
} else if (spinnerText == "Japanese Yen") {
|
83
|
-
currencyBtn.setOnClickListener(new View.OnClickListener() {
|
84
|
-
@Override
|
85
|
-
public void onClick(View view) {
|
86
|
-
selectedCurrency = spinnerText;
|
87
|
-
currencyChecked = currencyRemember.isChecked();
|
88
|
-
|
89
|
-
SharedPreferences.Editor editor = sharedPreferences.edit();
|
90
|
-
editor.putString("CURRENCY", selectedCurrency);
|
91
|
-
editor.putBoolean("CHECKBOX", currencyChecked);
|
92
|
-
editor.putInt(PREF_CURRENCY_VALUE, 1);
|
93
|
-
editor.commit();
|
94
|
-
Toast.makeText(BudgetTrackerSettingsActivity.this, "Currency Saved", Toast.LENGTH_SHORT).show();
|
95
|
-
|
96
|
-
Intent intent = new Intent(BudgetTrackerSettingsActivity.this, MainActivity.class);
|
97
|
-
startActivity(intent);
|
98
|
-
finish();
|
99
|
-
}
|
100
|
-
});
|
101
|
-
} else {
|
102
|
-
currencyBtn.setOnClickListener(new View.OnClickListener() {
|
103
|
-
@Override
|
104
|
-
public void onClick(View view) {
|
105
|
-
selectedCurrency = spinnerText;
|
106
|
-
currencyChecked = currencyRemember.isChecked();
|
107
|
-
|
108
|
-
SharedPreferences.Editor editor = sharedPreferences.edit();
|
109
|
-
editor.putString("CURRENCY", selectedCurrency);
|
110
|
-
editor.putBoolean("CHECKBOX", currencyChecked);
|
111
|
-
editor.putInt(PREF_CURRENCY_VALUE, 2);
|
112
|
-
editor.commit();
|
113
|
-
Toast.makeText(BudgetTrackerSettingsActivity.this, "Currency Saved", Toast.LENGTH_SHORT).show();
|
114
|
-
|
115
|
-
Intent intent = new Intent(BudgetTrackerSettingsActivity.this, MainActivity.class);
|
116
|
-
startActivity(intent);
|
117
|
-
finish();
|
118
|
-
}
|
119
|
-
});
|
120
|
-
}
|
121
|
-
Log.d("Currency", "onCreate: " + spinnerText);
|
122
78
|
}
|
123
79
|
|
124
80
|
@Override
|
@@ -126,6 +82,7 @@
|
|
126
82
|
spinnerText = null;
|
127
83
|
}
|
128
84
|
});
|
85
|
+
// spinner.setSelection(currency.ordinal());
|
129
86
|
}
|
130
87
|
|
131
88
|
|
@@ -244,17 +201,21 @@
|
|
244
201
|
}
|
245
202
|
|
246
203
|
```
|
247
|
-
|
204
|
+
HomeFragment.java (sharedPreferences 受け取り箇所)
|
205
|
+
※上記画像(Home画面)のCurrent Currency下のtextView
|
248
|
-
```ここに言語を入力
|
206
|
+
```ここに言語を入力
|
249
|
-
sharedPreferences = getSharedPreferences(
|
207
|
+
sharedPreferences = getActivity().getSharedPreferences(PREF_CURRENCY_FILENAME, 0);
|
208
|
+
|
250
|
-
|
209
|
+
//選択された通貨の設定
|
210
|
+
String currentCurrency = sharedPreferences.getString("CURRENCY", "");
|
251
|
-
|
211
|
+
int currentCurrencyNum = sharedPreferences.getInt("PREF_CURRENCY_VALUE", 0);
|
212
|
+
|
252
|
-
|
213
|
+
currentCurrencyTv.setText(currentCurrency);
|
253
|
-
if (
|
214
|
+
if (currentCurrencyNum == 0) {
|
254
|
-
ent
|
215
|
+
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_money, 0, 0, 0);
|
255
|
-
} else if (
|
216
|
+
} else if (currentCurrencyNum == 1) {
|
256
|
-
ent
|
217
|
+
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_yen, 0, 0, 0);
|
257
|
-
} else if (
|
218
|
+
} else if (currentCurrencyNum == 2) {
|
258
|
-
ent
|
219
|
+
currentCurrencyTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_euro, 0, 0, 0);
|
259
220
|
}
|
260
221
|
```
|
4
NewBudgetTrackerを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -244,3 +244,17 @@
|
|
244
244
|
}
|
245
245
|
|
246
246
|
```
|
247
|
+
NewBudgetTracker.java (sharedPreferences 受け取り箇所)
|
248
|
+
```ここに言語を入力
|
249
|
+
sharedPreferences = getSharedPreferences("CURRENCY_SHARED",0);
|
250
|
+
|
251
|
+
Integer selectedCurrencyNum = sharedPreferences.getInt("PREF_CURRENCY_VALUE", 0);
|
252
|
+
|
253
|
+
if (selectedCurrencyNum.equals(0)) {
|
254
|
+
enterPrice.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_money, 0, 0, 0);
|
255
|
+
} else if (selectedCurrencyNum.equals(1)) {
|
256
|
+
enterPrice.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_yen, 0, 0, 0);
|
257
|
+
} else if (selectedCurrencyNum.equals(2)) {
|
258
|
+
enterPrice.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_euro, 0, 0, 0);
|
259
|
+
}
|
260
|
+
```
|
3
Currency, CurrencySpinnerAdapterクラスを記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,6 +8,9 @@
|
|
8
8
|
|
9
9
|
よろしくお願いいたします。
|
10
10
|
|
11
|
+
追記:
|
12
|
+
状況を細かく共有するため、新たにCurrency, CurrencySpinnerAdapterクラスを記載しました。
|
13
|
+
|
11
14
|
図1(通貨設定画面)
|
12
15
|

|
13
16
|
|
@@ -18,33 +21,36 @@
|
|
18
21
|
```ここに言語を入力
|
19
22
|
package com.myproject.offlinebudgettrackerappproject;
|
20
23
|
|
21
|
-
import android.os.Bundle;
|
22
|
-
import
|
24
|
+
<import箇所は省略>
|
23
|
-
import android.view.View;
|
24
|
-
import android.widget.AdapterView;
|
25
|
-
import android.widget.Spinner;
|
26
|
-
import android.widget.Toast;
|
27
|
-
|
28
|
-
import androidx.appcompat.app.AppCompatActivity;
|
29
|
-
|
30
|
-
import com.myproject.offlinebudgettrackerappproject.adapter.CurrencySpinnerAdapter;
|
31
25
|
|
32
26
|
public class BudgetTrackerSettingsActivity extends AppCompatActivity {
|
33
27
|
|
34
28
|
Spinner spinner;
|
35
|
-
p
|
29
|
+
public static String spinnerText;
|
30
|
+
|
31
|
+
CheckBox currencyRemember;
|
32
|
+
Button currencyBtn;
|
36
33
|
Currency currency;
|
34
|
+
SharedPreferences sharedPreferences;
|
35
|
+
String selectedCurrency;
|
36
|
+
boolean currencyChecked;
|
37
|
+
private static final String PREF_CURRENCY_VALUE = "currencyValue";
|
37
38
|
|
38
39
|
@Override
|
39
40
|
protected void onCreate(Bundle savedInstanceState) {
|
40
41
|
super.onCreate(savedInstanceState);
|
41
42
|
setContentView(R.layout.activity_budget_tracker_settings);
|
42
43
|
Currency.initCurrencies();
|
44
|
+
|
43
45
|
spinner = (Spinner) findViewById(R.id.currency_spinner);
|
46
|
+
currencyRemember = (CheckBox) findViewById(R.id.currency_check_box);
|
47
|
+
currencyBtn = (Button) findViewById(R.id.currency_btn);
|
44
48
|
|
45
49
|
CurrencySpinnerAdapter currencySpinnerAdapter = new CurrencySpinnerAdapter(this, R.layout.currency_spinner_adopter,
|
46
50
|
Currency.getCurrencyArrayList());
|
47
51
|
spinner.setAdapter(currencySpinnerAdapter);
|
52
|
+
|
53
|
+
sharedPreferences = getSharedPreferences("CURRENCY_SHARED", 0);
|
48
54
|
|
49
55
|
|
50
56
|
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
@@ -54,10 +60,63 @@
|
|
54
60
|
spinnerText = currency.getCurrency();
|
55
61
|
if (spinnerText == "US Dollars") {
|
56
62
|
Toast.makeText(BudgetTrackerSettingsActivity.this, "US Dollars", Toast.LENGTH_SHORT).show();
|
63
|
+
currencyBtn.setOnClickListener(new View.OnClickListener() {
|
64
|
+
@Override
|
65
|
+
public void onClick(View view) {
|
66
|
+
selectedCurrency = spinnerText;
|
67
|
+
currencyChecked = currencyRemember.isChecked();
|
68
|
+
Vector<Vector<Float>> data = new Vector<Vector<Float>>();
|
69
|
+
|
70
|
+
SharedPreferences.Editor editor = sharedPreferences.edit();
|
71
|
+
editor.putString("CURRENCY", selectedCurrency);
|
72
|
+
editor.putBoolean("CHECKBOX", currencyChecked);
|
73
|
+
editor.putInt(PREF_CURRENCY_VALUE, 0);
|
74
|
+
editor.commit();
|
75
|
+
Toast.makeText(BudgetTrackerSettingsActivity.this, "Currency Saved", Toast.LENGTH_SHORT).show();
|
76
|
+
|
77
|
+
Intent intent = new Intent(BudgetTrackerSettingsActivity.this, MainActivity.class);
|
78
|
+
startActivity(intent);
|
79
|
+
finish();
|
80
|
+
}
|
81
|
+
});
|
57
82
|
} else if (spinnerText == "Japanese Yen") {
|
83
|
+
currencyBtn.setOnClickListener(new View.OnClickListener() {
|
84
|
+
@Override
|
85
|
+
public void onClick(View view) {
|
86
|
+
selectedCurrency = spinnerText;
|
87
|
+
currencyChecked = currencyRemember.isChecked();
|
88
|
+
|
89
|
+
SharedPreferences.Editor editor = sharedPreferences.edit();
|
90
|
+
editor.putString("CURRENCY", selectedCurrency);
|
91
|
+
editor.putBoolean("CHECKBOX", currencyChecked);
|
92
|
+
editor.putInt(PREF_CURRENCY_VALUE, 1);
|
93
|
+
editor.commit();
|
58
|
-
Toast.makeText(BudgetTrackerSettingsActivity.this, "
|
94
|
+
Toast.makeText(BudgetTrackerSettingsActivity.this, "Currency Saved", Toast.LENGTH_SHORT).show();
|
95
|
+
|
96
|
+
Intent intent = new Intent(BudgetTrackerSettingsActivity.this, MainActivity.class);
|
97
|
+
startActivity(intent);
|
98
|
+
finish();
|
99
|
+
}
|
100
|
+
});
|
59
101
|
} else {
|
102
|
+
currencyBtn.setOnClickListener(new View.OnClickListener() {
|
103
|
+
@Override
|
104
|
+
public void onClick(View view) {
|
105
|
+
selectedCurrency = spinnerText;
|
106
|
+
currencyChecked = currencyRemember.isChecked();
|
107
|
+
|
108
|
+
SharedPreferences.Editor editor = sharedPreferences.edit();
|
109
|
+
editor.putString("CURRENCY", selectedCurrency);
|
110
|
+
editor.putBoolean("CHECKBOX", currencyChecked);
|
111
|
+
editor.putInt(PREF_CURRENCY_VALUE, 2);
|
112
|
+
editor.commit();
|
60
|
-
Toast.makeText(BudgetTrackerSettingsActivity.this, "
|
113
|
+
Toast.makeText(BudgetTrackerSettingsActivity.this, "Currency Saved", Toast.LENGTH_SHORT).show();
|
114
|
+
|
115
|
+
Intent intent = new Intent(BudgetTrackerSettingsActivity.this, MainActivity.class);
|
116
|
+
startActivity(intent);
|
117
|
+
finish();
|
118
|
+
}
|
119
|
+
});
|
61
120
|
}
|
62
121
|
Log.d("Currency", "onCreate: " + spinnerText);
|
63
122
|
}
|
@@ -68,172 +127,120 @@
|
|
68
127
|
}
|
69
128
|
});
|
70
129
|
}
|
130
|
+
|
131
|
+
|
71
132
|
}
|
72
133
|
```
|
73
|
-
|
134
|
+
Currency.java
|
74
135
|
```ここに言語を入力
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
t
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
a
|
128
|
-
|
129
|
-
a
|
130
|
-
t
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
android:minHeight="48dp"
|
141
|
-
app:layout_constraintEnd_toEndOf="parent"
|
142
|
-
app:layout_constraintStart_toStartOf="parent"
|
143
|
-
app:layout_constraintTop_toBottomOf="@+id/enter_store_name"
|
144
|
-
android:drawableStart="@drawable/ic_product"
|
145
|
-
android:background="@drawable/custom_input"
|
146
|
-
android:paddingStart="5dp"
|
147
|
-
android:paddingEnd="5dp"
|
148
|
-
android:drawablePadding="12dp"
|
149
|
-
tools:ignore="SpeakableTextPresentCheck" />
|
150
|
-
|
151
|
-
<EditText
|
152
|
-
android:id="@+id/enter_product_type"
|
153
|
-
android:layout_width="wrap_content"
|
154
|
-
android:layout_height="wrap_content"
|
155
|
-
android:layout_marginTop="10dp"
|
156
|
-
android:ems="10"
|
157
|
-
android:hint="@string/new_budget_tracker_product_type_hint"
|
158
|
-
android:inputType="text"
|
159
|
-
android:minHeight="48dp"
|
160
|
-
app:layout_constraintEnd_toEndOf="parent"
|
161
|
-
app:layout_constraintStart_toStartOf="parent"
|
162
|
-
app:layout_constraintTop_toBottomOf="@+id/enter_product_name"
|
163
|
-
android:drawableStart="@drawable/ic_category"
|
164
|
-
android:background="@drawable/custom_input"
|
165
|
-
android:paddingStart="5dp"
|
166
|
-
android:paddingEnd="5dp"
|
167
|
-
android:drawablePadding="12dp"
|
168
|
-
tools:ignore="SpeakableTextPresentCheck" />
|
169
|
-
|
170
|
-
<EditText
|
171
|
-
android:id="@+id/enter_price"
|
172
|
-
android:layout_width="wrap_content"
|
173
|
-
android:layout_height="wrap_content"
|
174
|
-
android:layout_marginTop="10dp"
|
175
|
-
android:ems="10"
|
176
|
-
android:hint="@string/new_budget_tracker_price_hint"
|
177
|
-
android:inputType="number"
|
178
|
-
android:minHeight="48dp"
|
179
|
-
app:layout_constraintEnd_toEndOf="parent"
|
180
|
-
app:layout_constraintStart_toStartOf="parent"
|
181
|
-
app:layout_constraintTop_toBottomOf="@+id/enter_product_type"
|
182
|
-
android:drawableStart="@drawable/ic_money"
|
183
|
-
android:background="@drawable/custom_input"
|
184
|
-
android:paddingEnd="5dp"
|
185
|
-
android:drawablePadding="12dp"
|
186
|
-
tools:ignore="SpeakableTextPresentCheck" />
|
187
|
-
|
188
|
-
<Spinner
|
189
|
-
android:id="@+id/budget_tracker_spinner"
|
190
|
-
android:layout_width="210dp"
|
191
|
-
android:layout_height="50dp"
|
192
|
-
android:gravity="center"
|
193
|
-
android:minHeight="48dp"
|
194
|
-
android:layout_marginTop="10dp"
|
195
|
-
android:spinnerMode="dialog"
|
196
|
-
app:layout_constraintEnd_toEndOf="parent"
|
197
|
-
app:layout_constraintStart_toStartOf="parent"
|
198
|
-
app:layout_constraintTop_toBottomOf="@+id/enter_price"
|
199
|
-
tools:ignore="MissingConstraints,SpeakableTextPresentCheck" />
|
200
|
-
|
201
|
-
|
202
|
-
<Button
|
203
|
-
android:id="@+id/saveIndoButton"
|
204
|
-
android:layout_width="wrap_content"
|
205
|
-
android:layout_height="wrap_content"
|
206
|
-
android:layout_marginTop="28dp"
|
207
|
-
android:text="Save"
|
208
|
-
app:layout_constraintEnd_toEndOf="parent"
|
209
|
-
app:layout_constraintStart_toStartOf="parent"
|
210
|
-
android:background="@drawable/rounded_corner"
|
211
|
-
app:layout_constraintTop_toBottomOf="@+id/budget_tracker_spinner" />
|
212
|
-
|
213
|
-
<Button
|
214
|
-
android:id="@+id/delete_btn"
|
215
|
-
android:layout_width="wrap_content"
|
216
|
-
android:layout_height="wrap_content"
|
217
|
-
android:layout_marginTop="16dp"
|
218
|
-
android:text="Delete"
|
219
|
-
app:layout_constraintEnd_toEndOf="parent"
|
220
|
-
app:layout_constraintHorizontal_bias="0.5"
|
221
|
-
app:layout_constraintStart_toEndOf="@+id/update_btn"
|
222
|
-
android:background="@drawable/rounded_corner"
|
223
|
-
app:layout_constraintTop_toBottomOf="@+id/saveIndoButton" />
|
224
|
-
|
225
|
-
<Button
|
226
|
-
android:id="@+id/update_btn"
|
227
|
-
android:layout_width="wrap_content"
|
228
|
-
android:layout_height="wrap_content"
|
229
|
-
android:layout_marginTop="16dp"
|
230
|
-
android:text="Update"
|
231
|
-
app:layout_constraintEnd_toStartOf="@+id/delete_btn"
|
232
|
-
app:layout_constraintHorizontal_bias="0.5"
|
233
|
-
app:layout_constraintStart_toStartOf="parent"
|
234
|
-
android:background="@drawable/rounded_corner"
|
235
|
-
app:layout_constraintTop_toBottomOf="@+id/saveIndoButton" />
|
236
|
-
|
237
|
-
</androidx.constraintlayout.widget.ConstraintLayout>
|
136
|
+
package com.myproject.offlinebudgettrackerappproject;
|
137
|
+
|
138
|
+
<import箇所は省略>
|
139
|
+
|
140
|
+
public class Currency {
|
141
|
+
|
142
|
+
private static ArrayList<Currency> currencyArrayList = new ArrayList<>();
|
143
|
+
|
144
|
+
private String id;
|
145
|
+
private String currency;
|
146
|
+
|
147
|
+
public Currency(String id, String currency) {
|
148
|
+
this.id = id;
|
149
|
+
this.currency = currency;
|
150
|
+
}
|
151
|
+
|
152
|
+
public Currency() {
|
153
|
+
}
|
154
|
+
|
155
|
+
public String getId() {
|
156
|
+
return id;
|
157
|
+
}
|
158
|
+
|
159
|
+
public void setId(String id) {
|
160
|
+
this.id = id;
|
161
|
+
}
|
162
|
+
|
163
|
+
public String getCurrency() {
|
164
|
+
return currency;
|
165
|
+
}
|
166
|
+
|
167
|
+
public void setCurrency(String currency) {
|
168
|
+
this.currency = currency;
|
169
|
+
}
|
170
|
+
|
171
|
+
public static void initCurrencies() {
|
172
|
+
Currency usd = new Currency("0", "US Dollars");
|
173
|
+
currencyArrayList.add(usd);
|
174
|
+
|
175
|
+
Currency jpy = new Currency("1", "Japanese Yen");
|
176
|
+
currencyArrayList.add(jpy);
|
177
|
+
|
178
|
+
Currency euro = new Currency("2", "Euro");
|
179
|
+
currencyArrayList.add(euro);
|
180
|
+
|
181
|
+
|
182
|
+
}
|
183
|
+
|
184
|
+
public int getCurrencyImage() {
|
185
|
+
switch (getId()) {
|
186
|
+
case "0":
|
187
|
+
return R.drawable.ic_money;
|
188
|
+
case "1":
|
189
|
+
return R.drawable.ic_yen;
|
190
|
+
case "2":
|
191
|
+
return R.drawable.ic_euro;
|
192
|
+
}
|
193
|
+
return R.drawable.ic_money;
|
194
|
+
}
|
195
|
+
|
196
|
+
public static ArrayList<Currency> getCurrencyArrayList() {
|
197
|
+
return currencyArrayList;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
238
201
|
```
|
239
202
|
|
203
|
+
CurrencySpinnerAdapter.java
|
204
|
+
```ここに言語を入力
|
205
|
+
package com.myproject.offlinebudgettrackerappproject.adapter;
|
206
|
+
|
207
|
+
<import箇所は省略>
|
208
|
+
|
209
|
+
public class CurrencySpinnerAdapter extends ArrayAdapter<Currency> {
|
210
|
+
|
211
|
+
LayoutInflater layoutInflater;
|
212
|
+
|
213
|
+
public CurrencySpinnerAdapter(@NonNull Context context, int resource, @NonNull List<Currency> currencies) {
|
214
|
+
super(context, resource, currencies);
|
215
|
+
layoutInflater = LayoutInflater.from(context);
|
216
|
+
}
|
217
|
+
|
218
|
+
@NonNull
|
219
|
+
@Override
|
220
|
+
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
221
|
+
View rowView = layoutInflater.inflate(R.layout.currency_spinner_adopter, null, true);
|
222
|
+
Currency currency = getItem(position);
|
223
|
+
TextView textView = (TextView) rowView.findViewById(R.id.currency_name_textview);
|
224
|
+
ImageView imageView = (ImageView) rowView.findViewById(R.id.currency_symbol);
|
225
|
+
textView.setText(currency.getCurrency());
|
226
|
+
imageView.setImageResource(currency.getCurrencyImage());
|
227
|
+
return rowView;
|
228
|
+
}
|
229
|
+
|
230
|
+
@Override
|
231
|
+
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
232
|
+
if (convertView == null) {
|
233
|
+
convertView = layoutInflater.inflate(R.layout.currency_spinner_adopter, parent, false);
|
234
|
+
}
|
235
|
+
|
236
|
+
Currency currency = getItem(position);
|
237
|
+
TextView textView = (TextView) convertView.findViewById(R.id.currency_name_textview);
|
238
|
+
ImageView imageView = (ImageView) convertView.findViewById(R.id.currency_symbol);
|
239
|
+
textView.setText(currency.getCurrency());
|
240
|
+
imageView.setImageResource(currency.getCurrencyImage());
|
241
|
+
|
242
|
+
return convertView;
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
```
|
2
不可解な部分を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
下記スクショの通り、Spinnerを使って米ドル、日本円、ユーロから通貨を選べるようにしています。
|
3
3
|
ここでやりたいことは、上記Spinnerで選んだ通貨のシンボルでアプリ上の全ての金額に関わる部分に反映させることです。(例えば、ユーロであれば€のシンボルに)。
|
4
4
|
|
5
|
-
下記スクショの例では、図1の通貨設定画面で、例えば
|
5
|
+
下記スクショの例では、図1の通貨設定画面で、例えばEuroを選んだ場合、図2(購入商品入力画面)のEnter PriceのEditTextにデフォルトで設定されている$シンボルを€シンボルに変更するような仕様にしたいです。
|
6
6
|
|
7
7
|
通貨設定画面はBudgetTrackerSettingsActivity、購入商品入力画面NewBudgetTrackerと、それぞれ別々のActivityとなるので、BudgetTrackerSettingsActivityで設定した内容を、どのようにNewBudgetTracker含め、別のActivitやクラスに対して反映させるのか、ヒントがあればご教示ください。
|
8
8
|
|
1
誤字脱字を改修
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Androidの家計簿アプリをJavaで作成しています。
|
2
2
|
下記スクショの通り、Spinnerを使って米ドル、日本円、ユーロから通貨を選べるようにしています。
|
3
|
-
ここでやりたいことは、上記Spinnerで選んだ通貨のシンボル
|
3
|
+
ここでやりたいことは、上記Spinnerで選んだ通貨のシンボルでアプリ上の全ての金額に関わる部分に反映させることです。(例えば、ユーロであれば€のシンボルに)。
|
4
|
-
|
4
|
+
|
5
|
-
下記スクショの例では、図1の通貨設定画面で、例えばJapanse Yenを選んだ場合、図2(購入商品入力画面)のEnter PriceのEditTextに設定した$シンボルを
|
5
|
+
下記スクショの例では、図1の通貨設定画面で、例えばJapanse Yenを選んだ場合、図2(購入商品入力画面)のEnter PriceのEditTextに設定した$シンボルを円シンボルに変更するような仕様にしたいです。
|
6
6
|
|
7
7
|
通貨設定画面はBudgetTrackerSettingsActivity、購入商品入力画面NewBudgetTrackerと、それぞれ別々のActivityとなるので、BudgetTrackerSettingsActivityで設定した内容を、どのようにNewBudgetTracker含め、別のActivitやクラスに対して反映させるのか、ヒントがあればご教示ください。
|
8
8
|
|