質問編集履歴

7

一部のみのコード掲載よりコード全体の掲載・現在試行錯誤中のコード

2019/10/10 07:08

投稿

Curry_Rice
Curry_Rice

スコア35

test CHANGED
File without changes
test CHANGED
@@ -12,17 +12,181 @@
12
12
 
13
13
  以下が私のコードです。
14
14
 
15
+
16
+
17
+
18
+
19
+
20
+
21
+ import android.app.Activity;
22
+
23
+ import android.content.Intent;
24
+
25
+ import android.os.Bundle;
26
+
27
+ import android.view.View;
28
+
29
+ import android.widget.Button;
30
+
31
+
32
+
33
+
34
+
35
+ import android.widget.ArrayAdapter;
36
+
37
+ import android.widget.AdapterView;
38
+
39
+ import android.widget.ListView;
40
+
41
+ import android.database.Cursor;
42
+
43
+ import android.database.sqlite.SQLiteDatabase;
44
+
45
+
46
+
47
+ import android.widget.TextView;
48
+
49
+ import android.widget.Toast;
50
+
51
+
52
+
53
+ import java.util.ArrayList;
54
+
55
+ import java.util.HashMap;
56
+
57
+ import java.util.Map;
58
+
59
+
60
+
61
+
62
+
63
+ public class complist extends Activity {
64
+
65
+
66
+
67
+ private /*丙プロジェクトとアプリ名*/SimpleDatabaseHelper_bo1 helper = null;
68
+
69
+
70
+
71
+
72
+
73
+ @Override
74
+
75
+ protected void onCreate(Bundle savedInstanceState) {
76
+
77
+ super.onCreate(savedInstanceState);
78
+
79
+ setContentView(R.layout.complist_layout);
80
+
81
+
82
+
83
+
84
+
85
+ Integer pcontentid = 0;
86
+
87
+ String ptime = null;
88
+
89
+ String pname = null;
90
+
91
+
92
+
93
+ String stringid = null;
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ if (helper == null) {
102
+
103
+ helper = new SimpleDatabaseHelper_bo1(complist.this);
104
+
105
+ }
106
+
107
+
108
+
109
+
110
+
15
- final ArrayList<HashMap<String, String>> datalist1 = new ArrayList();
111
+ final ArrayList<HashMap<String, String>> datalist1 = new ArrayList();
112
+
16
-
113
+ // ArrayList datalist1 = new ArrayList();
114
+
115
+
116
+
117
+ SQLiteDatabase db1 = helper.getReadableDatabase();
118
+
119
+
120
+
121
+ try {
122
+
123
+
124
+
125
+ Cursor c3 = db1.rawQuery("SELECT * FROM "/*丙データベーステーブル名*/", null);
126
+
127
+ boolean next = c3.moveToFirst();
128
+
129
+ while (next) {
130
+
131
+ HashMap<String, String> data = new HashMap<>();
132
+
133
+
134
+
135
+ pcontentid = c3.getInt(0);
136
+
137
+ ptime = c3.getString(1);
138
+
139
+ pname = c3.getString(2);
140
+
141
+
142
+
143
+ stringid = String.valueOf(pcontentid);
144
+
145
+
146
+
147
+ data.put("ID", stringid);
148
+
149
+ data.put("Time", ptime);
150
+
151
+ data.put("Subject",pname);
152
+
153
+
154
+
155
+ datalist1.add(data);
156
+
157
+ next = c3.moveToNext();
158
+
159
+
160
+
17
-                 .
161
+ }
162
+
18
-
163
+ c3.close();
164
+
165
+
166
+
167
+ }catch (Exception e){
168
+
169
+
170
+
171
+ TextView error = (TextView)findViewById(R.id.textview_error);
172
+
173
+ error.setText(getString(R.string.not_yet));
174
+
175
+
176
+
177
+ } finally {
178
+
179
+ db1.close();
180
+
19
-                 .
181
+ }
20
-
21
-                 .
182
+
22
-
23
-
24
-
183
+
184
+
185
+
186
+
187
+
188
+
25
- final ArrayAdapter adapter = new ArrayAdapter(this,
189
+ final ArrayAdapter adapter = new ArrayAdapter(this,
26
190
 
27
191
  android.R.layout.simple_list_item_1,
28
192
 
@@ -32,11 +196,7 @@
32
196
 
33
197
 
34
198
 
35
-
36
-
37
-
38
-
39
- final ListView listView1 = (ListView) findViewById(R.id.listview1);
199
+ final ListView listView1 = (ListView) findViewById(R.id.listview1);
40
200
 
41
201
  listView1.setAdapter(adapter);
42
202
 
@@ -50,9 +210,19 @@
50
210
 
51
211
  >parent, View view, int position, long id){
52
212
 
213
+ /*
214
+
215
+ HashMap<String, String> map1 = (HashMap<String, String>)listView1.parentAdapter.getItemAtPosition(position);
216
+
217
+ String value1 = map1.get("ID");
218
+
219
+ String value2 = map1.get("Time");
220
+
221
+ String value3 = map1.get("Subject");
222
+
53
- try {
223
+ try {
54
-
224
+
55
- String item = (String) adapter.getItem(position);
225
+ String item = (String)map1.get(position);
56
226
 
57
227
  }catch (Exception e){
58
228
 
@@ -60,17 +230,23 @@
60
230
 
61
231
  }
62
232
 
233
+ */
234
+
235
+
236
+
63
- adapter.remove(adapter.getItem(position));
237
+ String item1 = (String)parent.getItemAtPosition(position) ;
238
+
239
+ datalist1.remove(item1);
240
+
241
+
64
242
 
65
243
  adapter.notifyDataSetChanged();
66
244
 
67
245
  return false;
68
246
 
69
-
70
-
71
-
72
-
73
-
247
+
248
+
249
+
74
250
 
75
251
  }
76
252
 
@@ -94,9 +270,9 @@
94
270
 
95
271
  String get_id2 = String.valueOf(id + 1);
96
272
 
97
- Intent intent4 = new Intent(this,
273
+ Intent intent4 = new Intent(complist.this,
98
-
274
+
99
- /*項目詳細のクラス*/);
275
+ user.win.hope.a_box_to_complain.compdisp.class);
100
276
 
101
277
  intent4.putExtra("did2",get_id2);
102
278
 
@@ -110,6 +286,16 @@
110
286
 
111
287
 
112
288
 
289
+ }
290
+
291
+
292
+
293
+ }
294
+
295
+
296
+
297
+
298
+
113
299
 
114
300
 
115
301
  項目を削除する前にダイアログも表示させたいのですが、項目自体が削除されないので、次に進めずにとても困っております。

6

2019/10/10 07:08

投稿

Curry_Rice
Curry_Rice

スコア35

test CHANGED
File without changes
test CHANGED
@@ -188,4 +188,8 @@
188
188
 
189
189
 
190
190
 
191
- itemにデータが入ってないのがどうしてなの、ここが怪しいのはないでしょうか…?
191
+ itemにデータが入ってきてないのは、間違ったキャストをしているすよね…?
192
+
193
+
194
+
195
+ キャストのExceptionがlogcatで出ておりますので、データのキャストをどうすれば良いのか、もし、お解りでいらっしゃいましたら、ご教授の程、お願い申し上げたい次第です。

5

2019/10/10 04:36

投稿

Curry_Rice
Curry_Rice

スコア35

test CHANGED
File without changes
test CHANGED
@@ -165,3 +165,27 @@
165
165
 
166
166
 
167
167
  のitemは「never used」と警告が出ております。
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ --------------------------------------
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+ 2019/10/10 PM13:25頃
184
+
185
+
186
+
187
+ HashMapを使わないで試してみましたが、うまくいきませんでした。
188
+
189
+
190
+
191
+ itemにデータが入ってこないのがどうしてなのか、ここが怪しいのではないでしょうか…?

4

2019/10/10 04:27

投稿

Curry_Rice
Curry_Rice

スコア35

test CHANGED
File without changes
test CHANGED
@@ -157,3 +157,11 @@
157
157
 
158
158
 
159
159
  現在、HashMapを使用せずにデータベースから項目のみ取得してリストビューに渡せるかどうか、試しております。
160
+
161
+
162
+
163
+ String item = (String)adapter.getItem(position)
164
+
165
+
166
+
167
+ のitemは「never used」と警告が出ております。

3

2019/10/10 03:59

投稿

Curry_Rice
Curry_Rice

スコア35

test CHANGED
File without changes
test CHANGED
@@ -136,6 +136,10 @@
136
136
 
137
137
 
138
138
 
139
+ --------------------------------------
140
+
141
+
142
+
139
143
 
140
144
 
141
145
  2019/10/10 PM12:40頃

2

2019/10/10 03:45

投稿

Curry_Rice
Curry_Rice

スコア35

test CHANGED
File without changes
test CHANGED
@@ -131,3 +131,25 @@
131
131
 
132
132
 
133
133
  ただのlistなら、adapter.removeで削除出来ても、データベースのデータを使う場合は、データベース自体のカラムも削除しなければならないのでしょうか…?
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+ 2019/10/10 PM12:40頃
142
+
143
+
144
+
145
+ 長押しで押されたitemを取得するときに、エラーで型が違うと表示されます。
146
+
147
+
148
+
149
+ HashMapを使っているので、keyとvalueの2つが必要なのに、無理やりStringでキャストしておりましたので、そこが問題でしょうか…?
150
+
151
+
152
+
153
+
154
+
155
+ 現在、HashMapを使用せずにデータベースから項目のみ取得してリストビューに渡せるかどうか、試しております。

1

2019/10/10 03:43

投稿

Curry_Rice
Curry_Rice

スコア35

test CHANGED
File without changes
test CHANGED
@@ -117,3 +117,17 @@
117
117
 
118
118
 
119
119
  もし、解決方法がお解りでいらっしゃいましたら、ご教授の程、宜しくお願い申し上げます。
120
+
121
+
122
+
123
+
124
+
125
+ 追伸
126
+
127
+
128
+
129
+ 今回のArraylistの項目にデータベースのデータを使用しており、短いクリックで項目の詳細画面にIntentしているのですが、その詳細画面で再び、データベースを開いて各々のデータを表示しております。
130
+
131
+
132
+
133
+ ただのlistなら、adapter.removeで削除出来ても、データベースのデータを使う場合は、データベース自体のカラムも削除しなければならないのでしょうか…?