質問編集履歴
2
コメントを挿入しました。変数の定義が分かりづらくてすいません
test
CHANGED
File without changes
|
test
CHANGED
@@ -112,8 +112,6 @@
|
|
112
112
|
|
113
113
|
|
114
114
|
|
115
|
-
// 忘れずに!
|
116
|
-
|
117
115
|
cursor.close();
|
118
116
|
|
119
117
|
|
@@ -134,11 +132,11 @@
|
|
134
132
|
|
135
133
|
values.put("company", com);
|
136
134
|
|
137
|
-
values.put("stockprice", price);
|
135
|
+
values.put("stockprice", price);//ここで日付挿入
|
138
136
|
|
139
137
|
|
140
138
|
|
141
|
-
db.insert("testdb", null, values);
|
139
|
+
db.insert("testdb", null, values);//ここでデータベース挿入
|
142
140
|
|
143
141
|
}
|
144
142
|
|
1
データベースについてのコードを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,6 +58,92 @@
|
|
58
58
|
|
59
59
|
```
|
60
60
|
|
61
|
+
```Java
|
62
|
+
|
63
|
+
private void readData(){
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
Log.d("debug","**********Cursor");
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
Cursor cursor = db.query(
|
72
|
+
|
73
|
+
"testdb",
|
74
|
+
|
75
|
+
new String[] { "company", "stockprice" },
|
76
|
+
|
77
|
+
null,
|
78
|
+
|
79
|
+
null,
|
80
|
+
|
81
|
+
null,
|
82
|
+
|
83
|
+
null,
|
84
|
+
|
85
|
+
null
|
86
|
+
|
87
|
+
);
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
cursor.moveToFirst();
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
StringBuilder sbuilder = new StringBuilder();
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
for (int i = 0; i < cursor.getCount(); i++) {
|
100
|
+
|
101
|
+
sbuilder.append(cursor.getString(0));
|
102
|
+
|
103
|
+
sbuilder.append(": ");
|
104
|
+
|
105
|
+
sbuilder.append(cursor.getInt(1));
|
106
|
+
|
107
|
+
sbuilder.append("\n");
|
108
|
+
|
109
|
+
cursor.moveToNext();
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
// 忘れずに!
|
116
|
+
|
117
|
+
cursor.close();
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
Log.d("debug","**********"+sbuilder.toString());
|
122
|
+
|
123
|
+
textView.setText(sbuilder.toString());
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
private void insertData(SQLiteDatabase db, String com, String price){
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
ContentValues values = new ContentValues();
|
134
|
+
|
135
|
+
values.put("company", com);
|
136
|
+
|
137
|
+
values.put("stockprice", price);
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
db.insert("testdb", null, values);
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
```
|
146
|
+
|
61
147
|
|
62
148
|
|
63
149
|
![実行結果](f5db247e52397190b15cf722ea98736d.png)
|