質問編集履歴
1
解決できたのでコードを追加で記載しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -241,3 +241,215 @@
|
|
241
241
|
何か根本的な理解が間違っているのでしょうか。。
|
242
242
|
|
243
243
|
表示/非表示の切り替え方をご存知の方、何卒ご教授のほどお願いいたします。
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
-----
|
248
|
+
|
249
|
+
ベストアンサーのyonaさんに教えて頂き、解決できました。
|
250
|
+
|
251
|
+
同様の問題の解決策を探している方のために、私が修正したコードを載せておこうと思います。
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
MainActivity.java
|
256
|
+
|
257
|
+
```Java
|
258
|
+
|
259
|
+
public class MainActivity extends AppCompatActivity {
|
260
|
+
|
261
|
+
// 名前
|
262
|
+
|
263
|
+
String[] mName = new String[] {
|
264
|
+
|
265
|
+
"osomatsu", "karamatsu", "choromatsu", "itimatsu", "jushimatsu", "todomatsu"
|
266
|
+
|
267
|
+
};
|
268
|
+
|
269
|
+
// 得点
|
270
|
+
|
271
|
+
String[] mScore = new String[] {
|
272
|
+
|
273
|
+
"60", "40", "30", "100", "20", "80"
|
274
|
+
|
275
|
+
};
|
276
|
+
|
277
|
+
private CustomAdapter ca;
|
278
|
+
|
279
|
+
private ListView lv;
|
280
|
+
|
281
|
+
private ArrayList<HashMap<String, String>> data;
|
282
|
+
|
283
|
+
private Activity act;
|
284
|
+
|
285
|
+
@Override
|
286
|
+
|
287
|
+
public void onCreate(Bundle savedInstanceState) {
|
288
|
+
|
289
|
+
super.onCreate(savedInstanceState);
|
290
|
+
|
291
|
+
setContentView(R.layout.main);
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
// ArrayList
|
296
|
+
|
297
|
+
data
|
298
|
+
|
299
|
+
= new ArrayList<HashMap<String, String>>();
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
// データ格納
|
304
|
+
|
305
|
+
for(int i = 0; i< 6; i++){
|
306
|
+
|
307
|
+
HashMap<String, String> map
|
308
|
+
|
309
|
+
= new HashMap<String, String>();
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
map.put("name", mName[i]);
|
314
|
+
|
315
|
+
map.put("score", mScore[i]);
|
316
|
+
|
317
|
+
if (mScore[i].equals("100")) {
|
318
|
+
|
319
|
+
map.put("result", "GREAT!");
|
320
|
+
|
321
|
+
} else {
|
322
|
+
|
323
|
+
map.put("result", "SO-SO");
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
data.add(map);
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
/*
|
332
|
+
|
333
|
+
* 作成したdataとカスタマイズしたレイアウトrow.xmlを
|
334
|
+
|
335
|
+
* 紐付けたSimpleAdapterを作成する
|
336
|
+
|
337
|
+
*/
|
338
|
+
|
339
|
+
ca
|
340
|
+
|
341
|
+
= new CustomAdapter(this
|
342
|
+
|
343
|
+
, data, R.layout.row,
|
344
|
+
|
345
|
+
new String[]{"name", "score", "result"},
|
346
|
+
|
347
|
+
new int[]{R.id.name, R.id.score, R.id.result}
|
348
|
+
|
349
|
+
);
|
350
|
+
|
351
|
+
// main.xmlのListViewにcaをセットします。
|
352
|
+
|
353
|
+
lv = (ListView)findViewById(R.id.listview);
|
354
|
+
|
355
|
+
lv.setAdapter(ca);
|
356
|
+
|
357
|
+
changeData(); // 後から値を変えてみるテスト
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
// 後から値を変えてみるテスト
|
364
|
+
|
365
|
+
public void changeData() {
|
366
|
+
|
367
|
+
HashMap<String, String> mMap
|
368
|
+
|
369
|
+
= new HashMap<String, String>();
|
370
|
+
|
371
|
+
mMap = data.get(2);
|
372
|
+
|
373
|
+
mMap.put("score", "100");
|
374
|
+
|
375
|
+
mMap.put("result", "GREAT!!");
|
376
|
+
|
377
|
+
data.set(2, mMap);
|
378
|
+
|
379
|
+
ca.notifyDataSetChanged();
|
380
|
+
|
381
|
+
}
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
class CustomAdapter extends SimpleAdapter {
|
388
|
+
|
389
|
+
LayoutInflater mLayoutInflater;
|
390
|
+
|
391
|
+
Context mContext;
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
public CustomAdapter(Context context,
|
396
|
+
|
397
|
+
List<? extends Map<String, ?>> data, int resource,
|
398
|
+
|
399
|
+
String[] from, int[] to) {
|
400
|
+
|
401
|
+
super(context, data, resource, from, to);
|
402
|
+
|
403
|
+
mContext = context;
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
@Override
|
410
|
+
|
411
|
+
public View getView(int position, View convertView, ViewGroup parent) {
|
412
|
+
|
413
|
+
mLayoutInflater = LayoutInflater.from(mContext);
|
414
|
+
|
415
|
+
convertView = mLayoutInflater.inflate(R.layout.row, parent, false);
|
416
|
+
|
417
|
+
ListView listView = (ListView)parent;
|
418
|
+
|
419
|
+
// get data
|
420
|
+
|
421
|
+
Map<String, Object> data = (Map<String, Object>)listView.getItemAtPosition(position);
|
422
|
+
|
423
|
+
// set items
|
424
|
+
|
425
|
+
TextView name = (TextView)convertView.findViewById(R.id.name);
|
426
|
+
|
427
|
+
name.setText((String)data.get("name"));
|
428
|
+
|
429
|
+
TextView score = (TextView)convertView.findViewById(R.id.score);
|
430
|
+
|
431
|
+
score.setText((String)data.get("score"));
|
432
|
+
|
433
|
+
String myScore = score.getText().toString();
|
434
|
+
|
435
|
+
TextView result = (TextView)convertView.findViewById(R.id.result);
|
436
|
+
|
437
|
+
result.setText((String)data.get("result"));
|
438
|
+
|
439
|
+
// edit visibility
|
440
|
+
|
441
|
+
if (myScore.equals("100")) {
|
442
|
+
|
443
|
+
result.setVisibility(View.VISIBLE);
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
return convertView;
|
448
|
+
|
449
|
+
}
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
```
|