소개
게시글
질문&답변
textview에 이미지 삽입하고 이미지만 클릭가능하게만들기
class MyViewHolder(private val binding: ItemListBinding):RecyclerView.ViewHolder(binding.root) { fun bind(item:Data) { with(binding) { tvId.text = item.Num tvTitle.text = item.title } } } myviewholder.kt class MyListAdapter:ListAdapter(MyDiffCallback()) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { val viewHolder = MyViewHolder( ItemListBinding.inflate( LayoutInflater.from(parent.context), parent, false ) ) return viewHolder } override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { if (holder is MyViewHolder) { val items = getItem(position) as Data holder.bind(items) } } } myListadapter.kt 이런식으로 짠 상태입니다. 아래가 item_list이구요.
- 0
- 3
- 386
질문&답변
badge에 관하여 질문드립니다.
package com.example.mytoproject.board import android.graphics.Color import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.BaseAdapter import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView import com.example.mytoproject.R import com.example.mytoproject.utils.FBAuth 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 org.w3c.dom.Text import java.text.SimpleDateFormat import java.util.* class BoardListLVAdapter(val boardList:MutableList): BaseAdapter() { private val database by lazy { FirebaseDatabase.getInstance() } private val userRef = database.getReference("board") override fun getCount(): Int { return boardList.size } override fun getItem(p0: Int): Any { return boardList[p0] } override fun getItemId(p0: Int): Long { return p0.toLong() } override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View { var view = p1 // if (view ==null) { view = LayoutInflater.from(p2?.context).inflate(R.layout.board_list_item,p2,false) //} val itemLinearLayoutview = view?.findViewById(R.id.itemview) val title = view?.findViewById(R.id.titleArea) title!!.text = boardList[p0].title val content = view?.findViewById(R.id.contentArea) content!!.text = boardList[p0].content val time = view?.findViewById(R.id.timeArea) time!!.text=boardList[p0].time val timestamp = view?.findViewById(R.id.BadgeIV) // if(boardList[p0].uid.equals(FBAuth.getUid())) { // itemLinearLayoutview?.setBackgroundColor(Color.parseColor("@values/mainColor")) // } if(get_timestmap().toInt() private fun getIgnoredTimeDays(time:Long):Long { return Calendar.getInstance().apply { timeInMillis=time set(Calendar.HOUR_OF_DAY,0) set(Calendar.MINUTE,0) set(Calendar.SECOND,0) set(Calendar.MILLISECOND,0) }.timeInMillis } 얘는 BoardListAdapter.kt 입니다
- 0
- 4
- 306
질문&답변
badge에 관하여 질문드립니다.
하나만 더 여쭈어 보겠습니다. 1.최초에 글 작성 버튼을 누르면 time stamp를 저장한다. private var timestamp = System.currentTimeMillis() binding.writeBtn.setOnClickListener { val title = binding.titleArea.text.toString() val contents = binding.contentsArea.text.toString() val uid = FBAuth.getUid() val time = FBAuth.getTime() val key = FBRef.boardRef.push().key.toString() FBRef.boardRef .child(key) .setValue(BoardModel(title, contents, uid, time, timestamp.toString())) } data class BoardModel( val title: String="", val content: String="", val uid: String="", val time: String="", val timestamp:String ="" ) 2. BoardListAdapter에서 연결한다. 여기서 좀 애를 먹고 있는데 이유는 데이터를 가져오는 정확한 방법을 잘 모르겠습니다. private val database by lazy { FirebaseDatabase.getInstance() } private val userRef = database.getReference("board") val timestamps = userRef.child("timestamp").toString() 파이어베이스 안에 timestamp는 잘 들어간 상태입니다 (사진) (사진) 요런식으로요.
- 0
- 4
- 306
질문&답변
리스트 뷰 실습 도중 에러가납니다.
원인을 찾았네요! parent로 선언이 안되어있고 p2로 되어있네용
- 0
- 1
- 215