質問編集履歴

1

質問内容に関係のないDialogd.ktを消し、activity_main.xmlを追加しました

2018/10/20 16:03

投稿

aNomoto
aNomoto

スコア12

test CHANGED
File without changes
test CHANGED
@@ -102,8 +102,6 @@
102
102
 
103
103
 
104
104
 
105
- //初期のリスト項目を設定
106
-
107
105
  val arrayAdapter = MyArrayAdapter(this, 0).apply{
108
106
 
109
107
  floatingActionButton.setOnClickListener {
@@ -118,8 +116,6 @@
118
116
 
119
117
  }
120
118
 
121
- //ListViewにリスト項目とArrayAdapterを設定
122
-
123
119
  val listView: ListView = findViewById(R.id.listView)
124
120
 
125
121
  listView.adapter = arrayAdapter
@@ -136,14 +132,12 @@
136
132
 
137
133
  class ListItem(val date_data:String){}
138
134
 
139
- //リスト項目を再利用するためのホルダー
135
+
140
136
 
141
137
  data class ViewHolder(val date_dataView: TextView,val morningIcon:ImageButton,val lunchIcon:ImageButton,val dinnerIcon:ImageButton)
142
138
 
143
139
 
144
140
 
145
- //自作のリスト項目データを扱えるようにしたArrayAdapter
146
-
147
141
  class MyArrayAdapter : ArrayAdapter<ListItem> {
148
142
 
149
143
  private var inflater : LayoutInflater? = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)as LayoutInflater?
@@ -162,7 +156,7 @@
162
156
 
163
157
 
164
158
 
165
- //再利用の設定
159
+
166
160
 
167
161
  if(view == null){
168
162
 
@@ -194,8 +188,6 @@
194
188
 
195
189
 
196
190
 
197
- //項目の情報設定
198
-
199
191
  val listItem = getItem(position)
200
192
 
201
193
  viewHolder.date_dataView.text =listItem!!.date_data
@@ -204,7 +196,7 @@
204
196
 
205
197
  viewHolder.morningIcon.setOnClickListener{
206
198
 
207
- //削除ボタンを押したときの処理
199
+
208
200
 
209
201
  this.remove(listItem)
210
202
 
@@ -224,93 +216,157 @@
224
216
 
225
217
 
226
218
 
227
- ```kotlin
228
-
229
- //Dialogs.kt
230
-
231
- package com.example.promoto.proc
232
-
233
-
234
-
235
- import android.app.DatePickerDialog
236
-
237
- import android.app.Dialog
238
-
239
- import android.content.Context
240
-
241
- import android.os.Bundle
242
-
243
- import android.support.v4.app.DialogFragment
244
-
245
- import android.widget.DatePicker
246
-
247
- import java.util.*
248
-
249
-
250
-
251
- class DatePickerFragment : DialogFragment(),
252
-
253
- DatePickerDialog.OnDateSetListener{
254
-
255
-
256
-
257
- interface OnDateSelectedListener{
258
-
259
- fun onSelected(year: Int,month: Int,date: Int)
260
-
261
- }
262
-
263
-
264
-
265
- private lateinit var listener: OnDateSelectedListener
266
-
267
-
268
-
269
- override fun onAttach(context: Context?){
270
-
271
- super.onAttach(context)
272
-
273
- if(context is OnDateSelectedListener){
274
-
275
- listener = context
276
-
277
- }
278
-
279
- }
280
-
281
-
282
-
283
- override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
284
-
285
- val c = Calendar.getInstance()
286
-
287
- val year = c.get(Calendar.YEAR)
288
-
289
- val month = c.get(Calendar.MONTH)
290
-
291
- val date =c.get(Calendar.DAY_OF_MONTH)
292
-
293
- return DatePickerDialog(context,this,year,month,date)
294
-
295
-
296
-
297
- }
298
-
299
-
300
-
301
- override fun onDateSet(view: DatePicker,year:Int,month: Int,date: Int) {
302
-
303
- listener.onSelected(year,month,date) //To change body of created functions use File | Settings | File Templates.
304
-
305
- }
306
-
307
- }
219
+
220
+
221
+ ```xml
222
+
223
+ //list_item.xml
224
+
225
+ <?xml version="1.0" encoding="utf-8"?>
226
+
227
+ <android.support.constraint.ConstraintLayout
228
+
229
+ xmlns:android="http://schemas.android.com/apk/res/android"
230
+
231
+ xmlns:tools="http://schemas.android.com/tools"
232
+
233
+ xmlns:app="http://schemas.android.com/apk/res-auto"
234
+
235
+ android:layout_width="match_parent"
236
+
237
+ android:layout_height="match_parent"
238
+
239
+ tools:context=".MainActivity">
240
+
241
+
242
+
243
+ <android.support.v7.widget.CardView
244
+
245
+ xmlns:android="http://schemas.android.com/apk/res/android"
246
+
247
+ xmlns:card_view="http://schemas.android.com/apk/res-auto"
248
+
249
+ android:layout_width="match_parent"
250
+
251
+ android:layout_height="135dp"
252
+
253
+ card_view:cardCornerRadius="4dp"
254
+
255
+ android:id="@+id/cardView"
256
+
257
+ tools:layout_editor_absoluteX="31dp"
258
+
259
+ card_view:layout_constraintTop_toTopOf="parent"
260
+
261
+ card_view:layout_constraintBottom_toBottomOf="parent">
262
+
263
+
264
+
265
+ <!-- カードに載せる情報 -->
266
+
267
+
268
+
269
+ <RelativeLayout
270
+
271
+ android:layout_width="match_parent"
272
+
273
+ android:layout_height="match_parent"
274
+
275
+ android:layout_gravity="center_horizontal"
276
+
277
+ android:id="@+id/cardRelative"
278
+
279
+ >
280
+
281
+ <Button
282
+
283
+ android:layout_width="65dp"
284
+
285
+ android:layout_height="match_parent"
286
+
287
+ android:textAllCaps="false" android:layout_alignParentStart="true"
288
+
289
+ android:layout_alignParentTop="true" android:layout_marginTop="0dp"
290
+
291
+ android:layout_marginStart="2dp" android:layout_alignParentBottom="true"
292
+
293
+ android:layout_marginBottom="0dp" android:textStyle="italic"
294
+
295
+ android:layout_toStartOf="@+id/morning_button" android:layout_marginRight="0dp"
296
+
297
+ android:layout_marginEnd="0dp" android:layout_toLeftOf="@+id/morning_button"
298
+
299
+ android:id="@+id/date_button" android:text="@string/date_button_text"/>
300
+
301
+ <ImageButton
302
+
303
+ android:layout_width="100dp"
304
+
305
+ android:layout_height="match_parent" app:srcCompat="@drawable/morning_icon"
306
+
307
+ android:id="@+id/morning_button"
308
+
309
+ android:layout_alignParentTop="true"
310
+
311
+ android:layout_marginTop="0dp" android:layout_alignParentBottom="true"
312
+
313
+ android:layout_marginBottom="0dp"
314
+
315
+ android:layout_toStartOf="@+id/lunch_button" android:layout_marginRight="2dp"
316
+
317
+ android:layout_marginEnd="2dp" android:layout_toLeftOf="@+id/lunch_button"/>
318
+
319
+ <ImageButton
320
+
321
+ android:layout_width="100dp"
322
+
323
+ android:layout_height="wrap_content" app:srcCompat="@drawable/lunch_icon"
324
+
325
+ android:id="@+id/lunch_button"
326
+
327
+ android:layout_alignParentTop="true" android:layout_marginTop="0dp"
328
+
329
+ android:layout_alignParentBottom="true" android:layout_marginBottom="0dp"
330
+
331
+ android:layout_toStartOf="@+id/dinner_button" android:layout_marginRight="2dp"
332
+
333
+ android:layout_marginEnd="2dp" android:layout_toLeftOf="@+id/dinner_button"/>
334
+
335
+ <ImageButton
336
+
337
+ android:layout_width="100dp"
338
+
339
+ android:layout_height="wrap_content" app:srcCompat="@drawable/dinner_icon"
340
+
341
+ android:id="@+id/dinner_button"
342
+
343
+ android:layout_alignParentTop="true" android:layout_marginTop="0dp"
344
+
345
+ android:layout_alignParentBottom="true"
346
+
347
+ android:layout_marginBottom="0dp"
348
+
349
+ android:layout_alignParentEnd="true" android:layout_alignParentRight="true"
350
+
351
+ android:layout_marginRight="5dp" android:layout_marginEnd="5dp"/>
352
+
353
+ </RelativeLayout>
354
+
355
+ </android.support.v7.widget.CardView>
356
+
357
+ </android.support.constraint.ConstraintLayout>
358
+
359
+
360
+
361
+
308
362
 
309
363
  ```
310
364
 
365
+
366
+
311
367
  ```xml
312
368
 
313
- //list_item.xml
369
+ //activity_main.xml
314
370
 
315
371
  <?xml version="1.0" encoding="utf-8"?>
316
372
 
@@ -330,136 +386,48 @@
330
386
 
331
387
 
332
388
 
333
- <android.support.v7.widget.CardView
389
+ <ListView
334
-
335
- xmlns:android="http://schemas.android.com/apk/res/android"
336
-
337
- xmlns:card_view="http://schemas.android.com/apk/res-auto"
338
390
 
339
391
  android:layout_width="match_parent"
340
392
 
341
- android:layout_height="135dp"
342
-
343
- card_view:cardCornerRadius="4dp"
344
-
345
- android:id="@+id/cardView"
346
-
347
- tools:layout_editor_absoluteX="31dp"
348
-
349
- card_view:layout_constraintTop_toTopOf="parent"
350
-
351
- card_view:layout_constraintBottom_toBottomOf="parent">
352
-
353
-
354
-
355
- <!-- カードに載せる情報 -->
356
-
357
-
358
-
359
- <RelativeLayout
360
-
361
- android:layout_width="match_parent"
362
-
363
- android:layout_height="match_parent"
364
-
365
- android:layout_gravity="center_horizontal"
366
-
367
- android:id="@+id/cardRelative"
368
-
369
- >
370
-
371
- <Button
372
-
373
- android:layout_width="65dp"
374
-
375
- android:layout_height="match_parent"
376
-
377
- android:textAllCaps="false" android:layout_alignParentStart="true"
378
-
379
- android:layout_alignParentTop="true" android:layout_marginTop="0dp"
380
-
381
- android:layout_marginStart="2dp" android:layout_alignParentBottom="true"
382
-
383
- android:layout_marginBottom="0dp" android:textStyle="italic"
384
-
385
- android:layout_toStartOf="@+id/morning_button" android:layout_marginRight="0dp"
386
-
387
- android:layout_marginEnd="0dp" android:layout_toLeftOf="@+id/morning_button"
388
-
389
- android:id="@+id/date_button" android:text="@string/date_button_text"/>
390
-
391
- <ImageButton
392
-
393
- android:layout_width="100dp"
394
-
395
- android:layout_height="match_parent" app:srcCompat="@drawable/morning_icon"
396
-
397
- android:id="@+id/morning_button"
398
-
399
- android:layout_alignParentTop="true"
400
-
401
- android:layout_marginTop="0dp" android:layout_alignParentBottom="true"
402
-
403
- android:layout_marginBottom="0dp"
404
-
405
- android:layout_toStartOf="@+id/lunch_button" android:layout_marginRight="2dp"
406
-
407
- android:layout_marginEnd="2dp" android:layout_toLeftOf="@+id/lunch_button"/>
408
-
409
- <ImageButton
410
-
411
- android:layout_width="100dp"
412
-
413
- android:layout_height="wrap_content" app:srcCompat="@drawable/lunch_icon"
414
-
415
- android:id="@+id/lunch_button"
416
-
417
- android:layout_alignParentTop="true" android:layout_marginTop="0dp"
418
-
419
- android:layout_alignParentBottom="true" android:layout_marginBottom="0dp"
420
-
421
- android:layout_toStartOf="@+id/dinner_button" android:layout_marginRight="2dp"
422
-
423
- android:layout_marginEnd="2dp" android:layout_toLeftOf="@+id/dinner_button"/>
424
-
425
- <ImageButton
426
-
427
- android:layout_width="100dp"
428
-
429
- android:layout_height="wrap_content" app:srcCompat="@drawable/dinner_icon"
430
-
431
- android:id="@+id/dinner_button"
432
-
433
- android:layout_alignParentTop="true" android:layout_marginTop="0dp"
434
-
435
- android:layout_alignParentBottom="true"
436
-
437
- android:layout_marginBottom="0dp"
438
-
439
- android:layout_alignParentEnd="true" android:layout_alignParentRight="true"
440
-
441
- android:layout_marginRight="5dp" android:layout_marginEnd="5dp"/>
442
-
443
- </RelativeLayout>
444
-
445
- </android.support.v7.widget.CardView>
393
+ android:layout_height="match_parent"
394
+
395
+ app:layout_constraintStart_toStartOf="parent"
396
+
397
+ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
398
+
399
+ app:layout_constraintTop_toTopOf="parent" android:id="@+id/listView"
400
+
401
+ app:layout_constraintHorizontal_bias="0.0" app:layout_constraintVertical_bias="1.0"/>
402
+
403
+ <android.support.design.widget.FloatingActionButton
404
+
405
+ android:layout_height="41dp"
406
+
407
+ android:clickable="true" app:srcCompat="@drawable/ic_add_black_24dp"
408
+
409
+ android:id="@+id/floatingActionButton"
410
+
411
+ android:layout_marginBottom="8dp"
412
+
413
+ app:layout_constraintBottom_toBottomOf="parent" android:layout_marginEnd="8dp"
414
+
415
+ app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp" android:layout_marginTop="8dp"
416
+
417
+ app:layout_constraintTop_toTopOf="parent" android:layout_marginStart="8dp"
418
+
419
+ app:layout_constraintStart_toStartOf="@+id/listView" android:layout_marginLeft="8dp"
420
+
421
+ app:layout_constraintHorizontal_bias="0.911" app:layout_constraintVertical_bias="0.96"
422
+
423
+ android:layout_width="41dp"/>
446
424
 
447
425
  </android.support.constraint.ConstraintLayout>
448
426
 
449
-
450
-
451
-
452
-
453
427
  ```
454
428
 
455
429
 
456
430
 
457
-
458
-
459
-
460
-
461
-
462
-
463
431
  ### 試したこと
464
432
 
465
433