작성
·
337
답변 4
0
댓글 달아주신데로
Invalidate Caches and Restart와
Clean Project / Rebuild Project를 실행해보았으나
동일하게 북마크에서 이미지가 나오지 않습니다.
안녕하세요 성현님
제 화면에서는 동일한 코드로 잘 나오는 것 같습니다.
컴퓨터 재부팅 / 안드로이드 스튜디오 재부팅 / 에뮬레이터 재부팅을 해서 한번 해보시겠어요?
안녕하세요 성현님
imageUrl 이 잘 안나오는 문제네요
대소문자 구분이 안되어서 인식을 못한 문제입니다.
ImageUrl -> imageUrl로 변경해줬는데 이 코드로 한번 해보시겠어요?
제가변경한 부분 코드 모두 첨부드립니다.
package com.qleks.mango_contents
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
class BookmarkActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private val contentModels = mutableListOf<ContentsModel>()
override fun onCreate(savedInstanceState: Bundle?) {
Log.d("BookmarkActivity", "onCreate")
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_bookmark)
auth = Firebase.auth
val database = Firebase.database
val myBookmarkRef = database.getReference("bookmark_ref")
val recyclerView = findViewById<RecyclerView>(R.id.rv)
val rvAdapter = RVAdapter(this,contentModels)
recyclerView.adapter = rvAdapter
myBookmarkRef.child(auth.currentUser?.uid.toString())
.addValueEventListener(object : ValueEventListener{
override fun onDataChange(snapshot: DataSnapshot) {
Log.d("BookmarkActivity", "onDataChange")
for (dataModel in snapshot.children) {
dataModel.getValue(ContentsModel::class.java)!!
Log.d("BookmarkActivity", dataModel.toString())
Log.d("BookmarkActivity3", dataModel.getValue(ContentsModel::class.java)!!.imageUrl)
Log.d("BookmarkActivity2", dataModel.toString())
contentModels.add(dataModel.getValue(ContentsModel::class.java)!!)
}
Log.d("contentModels", contentModels.toString())
rvAdapter.notifyDataSetChanged()
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})
recyclerView.layoutManager = GridLayoutManager(this, 2)
//test
}
}
package com.qleks.mango_contents
data class ContentsModel (
val url : String = "",
val imageUrl : String = "",
val titleText : String = ""
//test
)
package com.qleks.mango_contents
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.EditText
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
class JoinActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_join)
auth = Firebase.auth
val joinBtn = findViewById<Button>(R.id.joinBtn)
joinBtn.setOnClickListener {
val email = findViewById<EditText>(R.id.emailArea)
val password = findViewById<EditText>(R.id.passwordArea)
auth.createUserWithEmailAndPassword(email.text.toString(), password.text.toString())
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
} else {
// If sign in fails, display a message to the user.
Log.w("JOINActivity", "createUserWithEmail:failure", task.exception)
}
}
}
}
}
package com.qleks.mango_contents
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.TextureView
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class MainActivity : AppCompatActivity() {
private val items = mutableListOf<ContentsModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val bookmarkButton = findViewById<TextView>(R.id.bookmarkBtn)
bookmarkButton.setOnClickListener {
val intent = Intent(this, BookmarkActivity::class.java)
startActivity(intent)
}
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"1마라도 회식당"
)
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"2마라도 회식당"
)
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"3마라도 회식당"
)
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"4마라도 회식당"
)
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"5마라도 회식당"
)
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"6마라도 회식당"
)
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"7마라도 회식당"
)
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/wlvp5j7mpA",
"https://mp-seoul-image-production-s3.mangoplate.com/594757_1641012345552863.jpg?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"8마라도 회식당"
)
)
val recyclerView = findViewById<RecyclerView>(R.id.rv)
val rvAdapter = RVAdapter(this,items)
recyclerView.adapter = rvAdapter
rvAdapter.itemClick = object: RVAdapter.ItemClick{
override fun onClick(view: View, position: Int) {
val intent = Intent(baseContext, ViewActivity::class.java)
intent.putExtra("url", items[position].url)
intent.putExtra("title", items[position].titleText)
intent.putExtra("ImageUrl", items[position].imageUrl)
startActivity(intent)
}
}
recyclerView.layoutManager = GridLayoutManager(this, 2)
}
}
package com.qleks.mango_contents
import android.content.Context
import android.media.Image
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
class RVAdapter(val context : Context, val List : MutableList<ContentsModel>) : RecyclerView.Adapter<RVAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RVAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.rv_item, parent, false)
return ViewHolder(v)
}
interface ItemClick
{
fun onClick (view : View, position: Int)
}
var itemClick : ItemClick? = null
override fun onBindViewHolder(holder: RVAdapter.ViewHolder, position: Int) {
if (itemClick != null) {
holder?.itemView.setOnClickListener { v->
itemClick!!.onClick(v, position)
}
}
holder.bindItems(List[position])
}
override fun getItemCount(): Int {
return List.size
}
inner class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(item : ContentsModel) {
Log.d("Adapater", item.toString())
val rv_img = itemView.findViewById<ImageView>(R.id.rvImageArea)
val rv_text = itemView.findViewById<TextView>(R.id.rvTextArea)
rv_text.text = item.titleText
Glide.with(context)
.load(item.imageUrl)
.into(rv_img)
}
}
}
package com.qleks.mango_contents
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
class SplashActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
auth = Firebase.auth
if(auth.currentUser?.uid == null) {
Handler().postDelayed({
startActivity(Intent(this, JoinActivity::class.java))
finish()
}, 3000)
} else {
//가입된 회원므로, MainActivity 이동
Handler().postDelayed({
startActivity(Intent(this, MainActivity::class.java))
finish()
}, 3000)
}
}
}
package com.qleks.mango_contents
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
import android.widget.TextView
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
class ViewActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_view)
auth = Firebase.auth
val WebView = findViewById<WebView>(R.id.WebView)
WebView.loadUrl(intent.getStringExtra("url").toString())
// Write a message to the database
val database = Firebase.database
val myBookmarkRef = database.getReference("bookmark_ref")
val url = intent.getStringExtra("url").toString()
val title = intent.getStringExtra("title").toString()
val imageUrl = intent.getStringExtra("ImageUrl").toString()
val saveText = findViewById<TextView>(R.id.saveText)
saveText.setOnClickListener {
myBookmarkRef
.child(auth.currentUser!!.uid)
.push()
.setValue(ContentsModel(url, imageUrl, title))
}
}
}
대소문자관련 내용을 수정해보고, 혹시 안되면 올려주신 코드를 참조하겠습니다.
다행이 정상적으로 작동되었고,
대소문자 차이로 인해 이미지가 안불러졌는게 맞았습니다.
선생님 감사합니다.
0
안녕하세요. 선생님.
저도 이분과 동일한 문제를 격고 있습니다.
마지막 댓글처럼 에뮬레이터를 새롭게 만들어서 시도해보았지만 문제 해결은 되지 않았습니다.
github에 올려두었습니다. 체크 부탁드립니다.
안녕하세요
https://blog.daum.net/aldkzm/473
https://d2fault.github.io/2020/03/23/20200323-solving-r-error/
위의 글을 참고하셔서
File > Invalidate Caches
또는
Build > Clean Project / Rebuild Project
를 해보고시고 안되시면 스크린샷과 함께 한번 더 댓글 달아주시겠어요?
강사님 혹시 제가 혼자 복습하던 중 recycler view를 해보았는데 하나만 나오는 문제가 발생합니다... 아무리 봐도 어디가 문제인지 잘 모르겠는데 괜찮으시다면 조금만 도와주시면 너무 감사 할 것 같습니다.
0
package com.juho.seventh_project
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import com.google.firebase.database.ValueEventListener
class BookMarkActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private val contentModel = mutableListOf<ContentsModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_book_mark)
auth = Firebase.auth
val database = Firebase.database
val mybook_mark = database.getReference("bookmark_url")
val recycleView = findViewById<RecyclerView>(R.id.bookmark_rv)
val rvAdapter = RVAdapter(baseContext,contentModel)
recycleView.adapter = rvAdapter
recycleView.layoutManager = GridLayoutManager(this,2)
mybook_mark
.child(auth.currentUser?.uid.toString())
.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
for (dataModel in snapshot.children) {
contentModel.add(dataModel.getValue(ContentsModel::class.java)!!)
}
rvAdapter.notifyDataSetChanged()
}
override fun onCancelled(error: DatabaseError) {
Log.e("BookMark", "DB error")
}
})
}
}
package com.juho.seventh_project
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
class RVAdapter(val context : Context, val List : MutableList<ContentsModel>) : RecyclerView.Adapter<RVAdapter.ViewHolder>() {
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(item:ContentsModel){
val rv_img = itemView.findViewById<ImageView>(R.id.rvImage)
val rv_text = itemView.findViewById<TextView>(R.id.rvText)
rv_text.text = item.titleText
Glide.with(context)
.load(item.ImageUrl)
.into(rv_img)
}
}
interface ItemClick
{
fun onClick(view : View, position: Int)
}
var itemClick : ItemClick? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RVAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.recycler_view,parent,false)
return ViewHolder(v)
}
override fun onBindViewHolder(holder: RVAdapter.ViewHolder, position: Int) {
if(itemClick != null){
holder?.itemView.setOnClickListener { v->
itemClick!!.onClick(v, position)
}
}
holder.bindItems(List[position])
}
override fun getItemCount(): Int {
return List.size
}
}
ADAPTER
package com.juho.seventh_project
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class MainActivity : AppCompatActivity() {
private val items = mutableListOf<ContentsModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ",
"https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"매향")
)
val recyclerView = findViewById<RecyclerView>(R.id.rv)
val rvAdapter = RVAdapter(baseContext,items)
recyclerView.adapter = rvAdapter
rvAdapter.itemClick = object: RVAdapter.ItemClick{
override fun onClick(view: View, position: Int) {
val intent = Intent(baseContext,ViewActivity::class.java)
intent.putExtra("url",items[position].url)
intent.putExtra("title",items[position].titleText)
intent.putExtra("image",items[position].ImageUrl)
startActivity(intent)
}
}
//recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.layoutManager = GridLayoutManager(this,2)
val bookmark_Btn = findViewById<Button>(R.id.bookmark)
bookmark_Btn.setOnClickListener {
val book_intent = Intent(this,BookMarkActivity::class.java)
startActivity(book_intent)
}
}
}
안녕하세요 주호님
XML파일이 누락된 것 같아요
일단 보기에는 문제가 없어 보입니다.
예상되는 원인이 혹시 AndroidMinifest.xml 파일에
<uses-permission android:name="android.permission.INTERNET" />
를 추가하셨나요?
만약 잘 추가하셨는데도 안되시면
전체 프로젝트를 압축해서 공유해주세요.
여기 인프런 질문게시판에 전체 코드를 압축해서 올려주시거나, uyalae@naver.com 으로 보내주시겠어요?
깃허브에 올리시고 주소를 공유해주셔도 좋습니다.
안녕하세요
실행시켜보니 스플래시 화면에서 앱이 죽는 문제가 발생하네요.
혹시 아래에서 로그를 한번 찍어서 어떻게 Logcat화면에 나오는지 알려주실 수 있으실까요?
2022-02-17 18:53:08.933 3941-3941/com.juho.seventh_project D/RVAdapter: ContentsModel(url=https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ, ImageUrl=https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80, titleText=매향)
이렇게 나옵니다!
안녕하세요 주호님
url에 있는 주소
https://www.mangoplate.com/restaurants/0bz5Ual1g5XQ, ImageUrl=https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80
로 접근해보니 없어진 페이지라고 나옵니다.
다른 이미지 주소를 넣어서 시도해보시겠어요?
아래 주소를 이용해서 시도해보세요~
https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FsdxRl%2FbtrtwHLyqCJ%2FuBfSt88JRplI6LDzgy8jpk%2Fimg.png
https://mp-seoul-image-production-s3.mangoplate.com/329701/113339_1500385808720_113339_1500382497057_7184?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80
강사님 Image Url만 따서 하니까 잘 나옵니다...ㅠ 앱 Main에서도 사진이 잘 나오고요...
하지만 여전히 북마크에 추가해서 북마크로 넘어가면 사진만 나오질 않습니다...
성현님의 코드도 참고해봤는데...저랑 딱히 다른 점이 없습니다...
안녕하세요 주호님 아래의 성현님의 문제가 대소문자 구분 실수로 Firebase Image Url을 잘 불러오지 못하는 문제였습니다.
아래 코드를 공유드렸는데, Log.d 를 찍은 부분 참고해보시고 어려우시면 github에 코드 올려주신 후 주소 공유해주시면 제가 한번 살펴보겠습니다 :)
깃허브 사용법을 잘 모르시면 아래의 영상들 참고해주세요~
https://www.youtube.com/results?search_query=%EA%B9%83%ED%97%88%EB%B8%8C%EC%97%90+%EC%BD%94%EB%93%9C+%EC%98%AC%EB%A6%AC%EB%8A%94%EB%B2%95
0
안녕하세요
질문에
bookmark의 recycler view가 생성은 되는데 사진이 나오질 않습니다
이 부분이 무슨 뜻인지 이해가 어려운데, 안드로이드 폰 화면 스크린샷과 함께 좀 더 상세하게 알려주실 수 있으실까요?
Text는 나오는데 이미지는 안 나온다는 말씀이실까요?
선생님 코드와 비교해보아도 차이점은 보이지 않았고, 그 코드로 돌려보아도 화면이 나오지 않았습니다.