質問編集履歴

1

コードを追加しました

2021/10/23 14:17

投稿

sunnyblack
sunnyblack

スコア0

test CHANGED
File without changes
test CHANGED
@@ -28,6 +28,78 @@
28
28
 
29
29
  public class MainActivity extends AppCompatActivity {
30
30
 
31
+   @Override
32
+
33
+ protected void onResume() {
34
+
35
+ super.onResume();
36
+
37
+
38
+
39
+ selectDb();
40
+
41
+ }
42
+
43
+   public void selectDb() {
44
+
45
+ _helper = new DatabaseHelper(MainActivity.this);
46
+
47
+
48
+
49
+ SQLiteDatabase db = _helper.getWritableDatabase();
50
+
51
+
52
+
53
+ String[] projection = {
54
+
55
+ DatabaseContract._ID,
56
+
57
+ DatabaseContract.COLUMN_NAME_TITLE,
58
+
59
+ };
60
+
61
+
62
+
63
+ _cursor = db.query(
64
+
65
+ DatabaseContract.TABLE_NAME,
66
+
67
+ projection,
68
+
69
+ null,
70
+
71
+ null,
72
+
73
+ null,
74
+
75
+ null,
76
+
77
+ null
78
+
79
+ );
80
+
81
+
82
+
83
+ AACursorAdapter _adapter = new AACursorAdapter(MainActivity.this, _cursor);
84
+
85
+
86
+
87
+ ListView lvMemo = findViewById(R.id.lvMemo);
88
+
89
+
90
+
91
+ lvMemo.setAdapter(_adapter);
92
+
93
+
94
+
95
+ lvMemo.setOnItemClickListener(new ListItemClickListener());
96
+
97
+
98
+
99
+ lvMemo.setOnItemLongClickListener(new ListItemLongClickListener());
100
+
101
+ }
102
+
31
103
 
32
104
 
33
105
  private class ListItemClickListener implements AdapterView.OnItemClickListener{
@@ -94,6 +166,92 @@
94
166
 
95
167
 
96
168
 
169
+
170
+
171
+ AACursorAdapter:
172
+
173
+ ```Java
174
+
175
+ public class AACursorAdapter extends CursorAdapter {
176
+
177
+
178
+
179
+ private LayoutInflater mInflater;
180
+
181
+
182
+
183
+ public AACursorAdapter(Context context, Cursor cursor) {
184
+
185
+ super(context, cursor);
186
+
187
+
188
+
189
+ mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
190
+
191
+ }
192
+
193
+
194
+
195
+ static class ViewHolder {
196
+
197
+ TextView title;
198
+
199
+ }
200
+
201
+
202
+
203
+ @Override
204
+
205
+ public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
206
+
207
+ View view = mInflater.inflate(R.layout.memo_list_item, null);
208
+
209
+
210
+
211
+ ViewHolder holder = new ViewHolder();
212
+
213
+ holder.title = (TextView) view.findViewById(R.id.tvTitle);
214
+
215
+
216
+
217
+ view.setTag(holder);
218
+
219
+
220
+
221
+ return view;
222
+
223
+ }
224
+
225
+
226
+
227
+ @Override
228
+
229
+ public void bindView(View view, Context context, Cursor cursor) {
230
+
231
+ ViewHolder holder = (ViewHolder) view.getTag();
232
+
233
+
234
+
235
+ int memoId = cursor.getInt(0);
236
+
237
+ String memoTitle = cursor.getString(1);
238
+
239
+
240
+
241
+ holder.title.setText(memoTitle);
242
+
243
+ }
244
+
245
+
246
+
247
+ }
248
+
249
+ ```
250
+
251
+
252
+
253
+
254
+
97
255
  DeleteConfirmDialogFragment:
98
256
 
99
257
  ```Java