22.08.24 01:08 작성
·
227
0
안녕하세요. firebase 데이터 추가 강의 듣고 있습니다.
실행에 오류는 없는데 눌러도 데이터에 변화가 없습니다.
class ContentListActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_content_list)
// Write a message to the database
val database = Firebase.database
val myRef = database.getReference("contents")
myRef.push().setValue(
ContentModel("title1", "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FblYPPY%2Fbtq66v0S4wu%2FRmuhpkXUO4FOcrlOmVG4G1%2Fimg.png", "https://philosopher-chan.tistory.com/1235?category=941578")
)
myRef.push().setValue(
ContentModel("title2", "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FznKK4%2Fbtq665AUWem%2FRUawPn5Wwb4cQ8BetEwN40%2Fimg.png", "https://philosopher-chan.tistory.com/1236?category=941578")
)
myRef.push().setValue(
ContentModel("title3", "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbtig9C%2Fbtq65UGxyWI%2FPRBIGUKJ4rjMkI7KTGrxtK%2Fimg.png", "https://philosopher-chan.tistory.com/1237?category=941578")
)
val rv : RecyclerView = findViewById(R.id.rv) //리사이클 뷰 생성
// 데이터 삽입
val items = ArrayList<ContentModel>()
items.add(ContentModel("title1", "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FblYPPY%2Fbtq66v0S4wu%2FRmuhpkXUO4FOcrlOmVG4G1%2Fimg.png", "https://philosopher-chan.tistory.com/1235?category=941578"))
items.add(ContentModel("title2", "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FznKK4%2Fbtq665AUWem%2FRUawPn5Wwb4cQ8BetEwN40%2Fimg.png", "https://philosopher-chan.tistory.com/1236?category=941578"))
items.add(ContentModel("title3", "https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbtig9C%2Fbtq65UGxyWI%2FPRBIGUKJ4rjMkI7KTGrxtK%2Fimg.png", "https://philosopher-chan.tistory.com/1237?category=941578"))
val rvAdapter = ContentRVAdapter(baseContext, items) //어뎁터 생성
rv.adapter = rvAdapter
rv.layoutManager = GridLayoutManager(this, 2)
rvAdapter.itemClick = object : ContentRVAdapter.ItemClick{
override fun onClick(view: View, position: Int) {
Toast.makeText(baseContext, items[position].title, Toast.LENGTH_LONG).show()
val intent = Intent(this@ContentListActivity, ContentShowActivity::class.java)
//url 넘겨주기
intent.putExtra("url", items[position].webUrl)
startActivity(intent)
}
}
}
}
답변 2
0
2022. 08. 27. 23:48
Hajin-Lee0406/sololife (github.com)
깃허브에 올려두었습니다.