작성
·
175
0
DetailViewFragment 코틀린파일안에 onCreateView 메소드 에서 구현하는
view.findViewById<RecyclerView>(R.id.detailviewfragment_recyclerview).adapter = DetailViewRecyclerViewAdapter()
view.findViewById<RecyclerView>(R.id.detailviewfragment_recyclerview).layoutManager = LinearLayoutManager(activity)
이 부분중 findViewById부분이 노란색으로 표시되면서
The id R.id.detailviewfragment_recyclerview has already been looked up in this method; possible cut & paste error? (First usage here)
이런 메시지가 뜹니다.
그러면서 아래와같이 코드를 오류없이 따라 쳤는데 게시글부분이 나오질 않습니다.
앱을 실행해도 에러없이 켜지고 동작은하는데 게시글이 나오지 않습니다.
Firebase store 부분에도 폴더가 만들어져있고 업로드한 파일이 잘 들어가 있습니다.
class DetailViewFragment : Fragment() {
var firestore: FirebaseFirestore? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = LayoutInflater.from(activity).inflate(R.layout.fragment_detail, container, false)
firestore = FirebaseFirestore.getInstance()
view.findViewById<RecyclerView>(R.id.detailviewfragment_recyclerview).adapter = DetailViewRecyclerViewAdapter()
view.findViewById<RecyclerView>(R.id.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("image")?.orderBy("timestamp")
?.addSnapshotListener { querySnapshot, firebaseFirestoreException ->
contentDTOs.clear()
contentUidList.clear()
for (snapshot in querySnapshot!!.documents) {
val item = snapshot.toObject(ContentDTO::class.java)
contentDTOs.add(item!!)
contentUidList.add(snapshot.id)
}
notifyDataSetChanged()
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val 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 onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val viewholder = (holder as CustomViewHolder).itemView
//User id
viewholder.findViewById<TextView>(R.id.detailviewitem_profile_textview).text = contentDTOs[position].userId
//Image
Glide.with(holder.itemView.context).load(contentDTOs[position].imageUrl).into(viewholder.findViewById(R.id.detailviewitem_imageview_content))
//Explain of content
viewholder.findViewById<TextView>(R.id.detailviewitem_explain_textview).text = contentDTOs[position].explain
//likes
viewholder.findViewById<TextView>(R.id.detailviewitem_favoritecounter_textview).text = "Likes" + contentDTOs!![position].favoriteCount
//Profile Image
Glide.with(holder.itemView.context).load(contentDTOs[position].imageUrl).into(viewholder.findViewById(R.id.detailviewitem_profile_image))
}
override fun getItemCount(): Int {
return contentDTOs.size
}
}
}
답변 1
0
노란색으로 표시되는건 경고로 사실 앱 자동에는 영향을 주지 않습니다. 쿼리가 이상한듯한데 addSnapshotListener 결과값이 정상적으로 넘어오는지 확인해야할 것 같습니다.