CFragment.kt
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.example.vip
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import kotlinx.android.synthetic.main.fragment_a.*
class CFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_a, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val policyList = ArrayList<PolicyItem>()
var recomdatabase = FirebaseDatabase.getInstance().reference
recomdatabase.orderByChild("View").addListenerForSingleValueEvent(object :
ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
//Toast.makeText(this@RecommendActivity, "실패부분", Toast.LENGTH_SHORT).show()
}
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (memoSnapshot in dataSnapshot.children){
val memo = memoSnapshot.getValue(MemoItemRecom::class.java)
policyList.add(
PolicyItem(
ContextCompat.getDrawable(context!!.applicationContext, R.drawable.recommend_default_blue)!!,
memo!!.Policy,
memo!!.Content,
memo!!.Link,
memo!!.View,
memo!!.Keyword,
memo!!.Date,
memo!!.Review,
memo!!.Score,
memo!!.Category1,
memo!!.Category2,
memo!!.Category3,
memo!!.Category4,
memo!!.Category5,
memo!!.Category6,
memo!!.Category7,
memo!!.Category8,
memo!!.Category9,
memo!!.Category10,
memo!!.Category11,
memo!!.Category12,
memo!!.Category13,
memo!!.Category14,
memo!!.Category15,
memo!!.Category16,
memo!!.Value,
memo!!.D_day
)
)
}
val adapter = PolicyAdapter(policyList)
policyRecyclerView.adapter = adapter
policyRecyclerView.setItemViewCacheSize((200000000))
}
})
}
}