작성
·
295
0
'상세화면 페이지 만들기' 강의를 공부하는 중입니다.
코드를 그대로 받아적었는데도,
앱을 실행하면 메인화면에 게시글이 뜨지 않습니다.
DetailViewFragment.kt 코드를 아래와 같이 작성하였습니다.
package com.example.instaclone.navigation
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.instaclone.R
import com.example.instaclone.navigation.model.ContentDTO
import com.google.firebase.firestore.FirebaseFirestore
import kotlinx.android.synthetic.main.fragment_detail.view.*
import kotlinx.android.synthetic.main.item_detail.view.*
class DetailViewFragment : Fragment() {
var firestore: FirebaseFirestore? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var view = LayoutInflater.from(activity).inflate(R.layout.fragment_detail, container, false)
firestore = FirebaseFirestore.getInstance()
view.detailviewfragment_recyclerview.adapter = DetailViewRecyclerViewAdapter()
view.detailviewfragment_recyclerview.layoutManager = LinearLayoutManager(activity)
return view
}
inner class DetailViewRecyclerViewAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var contentDTOs: ArrayList<ContentDTO> = arrayListOf()
var contentUidList: ArrayList<String> = arrayListOf()
init {
firestore?.collection("images")?.orderBy("timestamp")?.addSnapshotListener { querySnapshot, firebaseFirestoreException ->
contentDTOs.clear()
contentUidList.clear()
for (snapshot in querySnapshot!!.documents) {
var item = snapshot.toObject(ContentDTO::class.java)
contentDTOs.add(item!!)
contentUidList.add(snapshot.id)
}
notifyDataSetChanged()
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
var view = LayoutInflater.from(parent.context).inflate(R.layout.item_detail, parent, false)
return CustomViewHolder(view)
}
inner class CustomViewHolder(view: View) : RecyclerView.ViewHolder(view)
override fun getItemCount(): Int {
return contentDTOs.size
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
var viewholder = (holder as CustomViewHolder).itemView
// User Id
viewholder.detailviewitem_profile_textview.text = contentDTOs!![position].userId
// Image
Glide.with(holder.itemView.context).load(contentDTOs!![position].imageUrl).into(viewholder.detailviewitem_imageview_content)
// Explain
viewholder.detailviewitem_explain_textview.text = contentDTOs!![position].explain
// likes
viewholder.detailviewitem_favoritecounter_textview.text = "Likes "+ contentDTOs!![position].favoriteCount
// ProfileImage
Glide.with(holder.itemView.context).load(contentDTOs!![position].imageUrl).into(viewholder.detailviewitem_profile_image)
}
}
}
답변 5
1
1
0
0
8강에 오타가 있습니다.
강의에 images 로 되어있는데 image로 고치면 게시물이 나오기는 합니다.
근데 다 정상으로 나오지는 않습니다.
inner class DetailViewRecyclerViewAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>(){
var contentDTO : ArrayList<ContentDTO> = arrayListOf()
var contentUidList : ArrayList<String> = arrayListOf()
init {
firestore?.collection("image")?.orderBy("timestamp")?.addSnapshotListener {querySnapshot , firebaseFirestoreExcetion ->
contentDTO.clear()
contentUidList.clear()
for(snapshot in querySnapshot!!.documents){
var item = snapshot.toObject(ContentDTO::class.java)
contentDTO.add(item!!)
contentUidList.add(snapshot.id)
}
notifyDataSetChanged()
}
}
0