質問編集履歴
3
内容の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
AutoCompleteTextViewに
|
1
|
+
AutoCompleteTextViewで選択した行のデータではなく最後に登録したデータが表示される
|
test
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
AutoCompleteTextView
|
1
|
+
SQLiteの登録情報の反映をさせたAutoCompleteTextViewでデータ1(列0)の情報を選択して、ボタンを押下すると
|
2
2
|
|
3
|
+
textViewに列2、列3、、、と反映されて表示させたいです
|
4
|
+
|
3
|
-
|
5
|
+
しかし、ボタン押下後に表示されるデータが他の行のデータのものになってしまいます。
|
6
|
+
|
7
|
+
選択した行のデータを反映させる方法についてご教授お願い致します。
|
8
|
+
|
9
|
+
|
4
10
|
|
5
11
|
```errormsg
|
6
12
|
|
@@ -16,15 +22,19 @@
|
|
16
22
|
|
17
23
|
|
18
24
|
|
25
|
+
private String foodName = "";
|
26
|
+
|
27
|
+
private int id = 0;
|
28
|
+
|
19
|
-
private double foodgram = 0.0d;
|
29
|
+
private double foodgram = 0.0d;
|
20
30
|
|
21
31
|
private double calorie = 0.0d;
|
22
32
|
|
23
33
|
private double protain = 0.0d;
|
24
34
|
|
25
|
-
|
35
|
+
private double carbon = 0.0d;
|
26
36
|
|
27
|
-
private double
|
37
|
+
private double fat = 0.0d;
|
28
38
|
|
29
39
|
|
30
40
|
|
@@ -56,17 +66,17 @@
|
|
56
66
|
|
57
67
|
int i = 0;
|
58
68
|
|
69
|
+
while (cr.moveToNext()) {
|
70
|
+
|
71
|
+
|
72
|
+
|
59
|
-
d
|
73
|
+
id = cr.getInt(0);
|
60
74
|
|
61
75
|
mydata[i] = cr.getString(1);
|
62
76
|
|
63
77
|
i ++;
|
64
78
|
|
65
|
-
}while (cr.moveToNext()); {
|
66
|
-
|
67
|
-
int id = cr.getInt(0); //この行に対してerrormsg
|
68
|
-
|
69
|
-
|
79
|
+
foodName = cr.getString(1);
|
70
80
|
|
71
81
|
foodgram = cr.getDouble(2);
|
72
82
|
|
@@ -76,9 +86,13 @@
|
|
76
86
|
|
77
87
|
carbon = cr.getDouble(5);
|
78
88
|
|
79
|
-
fat = cr.getDouble(6);
|
89
|
+
fat = cr.getDouble(6);
|
90
|
+
|
91
|
+
|
80
92
|
|
81
93
|
}
|
94
|
+
|
95
|
+
|
82
96
|
|
83
97
|
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.requireActivity(),
|
84
98
|
|
@@ -96,6 +110,58 @@
|
|
96
110
|
|
97
111
|
}
|
98
112
|
|
113
|
+
|
114
|
+
|
115
|
+
@Override
|
116
|
+
|
117
|
+
public void onResume() {
|
118
|
+
|
119
|
+
super.onResume();
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
mydb = new MySQLiteOpenHelper(requireActivity());
|
124
|
+
|
125
|
+
db = mydb.getReadableDatabase();
|
126
|
+
|
127
|
+
final String [] mydata;
|
128
|
+
|
129
|
+
ArrayList<String> array = new ArrayList<>();
|
130
|
+
|
131
|
+
String sql = "SELECT * FROM Products";
|
132
|
+
|
133
|
+
Cursor cr = db.rawQuery(sql, null);
|
134
|
+
|
135
|
+
cr.moveToFirst();
|
136
|
+
|
137
|
+
mydata = new String[cr.getCount()];
|
138
|
+
|
139
|
+
int i = 0;
|
140
|
+
|
141
|
+
do {
|
142
|
+
|
143
|
+
mydata[i] = cr.getString(1);
|
144
|
+
|
145
|
+
i ++;
|
146
|
+
|
147
|
+
}while (cr.moveToNext());
|
148
|
+
|
149
|
+
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.requireActivity(),
|
150
|
+
|
151
|
+
android.R.layout.simple_dropdown_item_1line, mydata);
|
152
|
+
|
153
|
+
foodlist1.setAdapter(adapter);
|
154
|
+
|
155
|
+
foodlist2.setAdapter(adapter);
|
156
|
+
|
157
|
+
foodlist3.setAdapter(adapter);
|
158
|
+
|
159
|
+
foodlist4.setAdapter(adapter);
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
99
165
|
}
|
100
166
|
|
101
167
|
```
|
2
内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,6 +92,12 @@
|
|
92
92
|
|
93
93
|
foodlist4.setAdapter(adapter);
|
94
94
|
|
95
|
+
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
95
101
|
```
|
96
102
|
|
97
103
|
while文の中のcr.get()文を全て削除すると新規データも反映されるのですが、
|
1
内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,31 @@
|
|
12
12
|
|
13
13
|
```pagefragment1
|
14
14
|
|
15
|
+
public class PageFragment1 extends Fragment {
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
private double foodgram = 0.0d;
|
20
|
+
|
21
|
+
private double calorie = 0.0d;
|
22
|
+
|
23
|
+
private double protain = 0.0d;
|
24
|
+
|
25
|
+
private double fat = 0.0d;
|
26
|
+
|
27
|
+
private double carbon = 0.0d;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
@Override
|
32
|
+
|
33
|
+
public void onViewCreated(View view, Bundle savedInstanceState) {
|
34
|
+
|
35
|
+
super.onViewCreated(view, savedInstanceState);
|
36
|
+
|
37
|
+
|
38
|
+
|
15
|
-
//データベースの取り込み
|
39
|
+
//データベースの取り込み
|
16
40
|
|
17
41
|
mydb = new MySQLiteOpenHelper(requireActivity());
|
18
42
|
|
@@ -50,9 +74,9 @@
|
|
50
74
|
|
51
75
|
protain = cr.getDouble(4);
|
52
76
|
|
53
|
-
|
77
|
+
carbon = cr.getDouble(5);
|
54
78
|
|
55
|
-
|
79
|
+
fat = cr.getDouble(6);
|
56
80
|
|
57
81
|
}
|
58
82
|
|