質問編集履歴
1
質問の補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,3 +25,89 @@
|
|
25
25
|
|
26
26
|
|
27
27
|
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```adpter
|
32
|
+
|
33
|
+
class ScheduleAdapter(data: OrderedRealmCollection<Schedule>) :
|
34
|
+
|
35
|
+
RealmRecyclerViewAdapter<Schedule, ScheduleAdapter.ViewHolder>(data, true) {
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
private var listener: ((Long?) -> Unit)? = null
|
40
|
+
|
41
|
+
fun setOnItemClickListener(listener: (Long?) -> Unit) {
|
42
|
+
|
43
|
+
this.listener = listener
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
init {
|
50
|
+
|
51
|
+
setHasStableIds(true)
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
class ViewHolder(cell: View) : RecyclerView.ViewHolder(cell) { //RecylerViewを継承
|
58
|
+
|
59
|
+
val date: TextView = cell.findViewById(android.R.id.text1)
|
60
|
+
|
61
|
+
val title: TextView = cell.findViewById(android.R.id.text2)
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ScheduleAdapter.ViewHolder {
|
68
|
+
|
69
|
+
val infrater = LayoutInflater.from(parent.context) //インスタンス生成
|
70
|
+
|
71
|
+
val view = infrater.inflate( //ビューにレイアウトXMLを適用
|
72
|
+
|
73
|
+
android.R.layout.simple_list_item_2,
|
74
|
+
|
75
|
+
parent, false
|
76
|
+
|
77
|
+
)
|
78
|
+
|
79
|
+
return ViewHolder(view)
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
////////////////////////// //データを取り出し表示させるための処理/////////////
|
86
|
+
|
87
|
+
override fun onBindViewHolder(holder: ScheduleAdapter.ViewHolder, position: Int) {
|
88
|
+
|
89
|
+
val schedule: Schedule? = getItem(position)
|
90
|
+
|
91
|
+
holder.date.text = DateFormat.format("yyyy/MM/dd", schedule?.date)
|
92
|
+
|
93
|
+
holder.title.text = schedule?.title
|
94
|
+
|
95
|
+
holder.itemView.setOnClickListener {
|
96
|
+
|
97
|
+
listener?.invoke(schedule?.id)
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
override fun getItemId(position: Int): Long { //getItemIdをオーバーライド
|
106
|
+
|
107
|
+
return getItem(position)?.id ?: 0
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
```
|