인프런 커뮤니티 질문&답변

dudah754님의 프로필 이미지

작성한 질문수

[왕초보편] 앱 8개를 만들면서 배우는 안드로이드 코틀린(Android Kotlin)

RecyclerView 꾸며보기

사진이 안나와요

21.08.24 12:16 작성

·

236

0

메니페스트.xml에 

<uses-permission android:name="android.permission.INTERNET"/>



이 코드를 추가했는데도 사진이 뜨질 않네요

답변 6

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

2021. 08. 27. 01:21

rv_item.xml

ContentsModel.kt

2개의 파일이 누락된 것 같습니다.

파일끼리 서로 연관이 있기 때문에 모두 올려주셔야 해요~

혹시 강의자료에 있는 소스코드와 비교는 해보셨을까요~?

0

dudah754님의 프로필 이미지
dudah754
질문자

2021. 08. 26. 19:53

이렇게 올려드리면 될까요??

RVadpater

package com.kkk.mango_content

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.appcompat.view.menu.ActionMenuItemView
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){

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)

}
}


}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#ff7f00"
>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity

package com.kkk.mango_content

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.GridLayout
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/08OQhkbuBywp",
"https://mp-seoul-image-production-s3.mangoplate.com/232277/1656652_1629454183714_37422?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"오리지널팬케이크하우스"
)
)

items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/yuX1m8atSUXR",
"https://mp-seoul-image-production-s3.mangoplate.com/528686_1535270828863873.jpg",
"비스티버거"
)
)

items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/UvljRiCMYhwh",
"https://mp-seoul-image-production-s3.mangoplate.com/2925_1611070563111484.jpg",
"BOWL ROOM"
)
)

items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/asbzWXaJjd",
"https://mp-seoul-image-production-s3.mangoplate.com/106666/694014_1561453641850_4592?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"고기리막국수"
)
)

items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/08OQhkbuBywp",
"https://mp-seoul-image-production-s3.mangoplate.com/232277/1656652_1629454183714_37422?fit=around|512:512&crop=512:512;*,*&output-format=jpg&output-quality=80",
"오리지널팬케이크하우스"
)
)

items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/yuX1m8atSUXR",
"https://mp-seoul-image-production-s3.mangoplate.com/528686_1535270828863873.jpg",
"비스티버거"
)
)

items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/UvljRiCMYhwh",
"https://mp-seoul-image-production-s3.mangoplate.com/2925_1611070563111484.jpg",
"BOWL ROOM"
)
)

items.add(
ContentsModel(
"https://www.mangoplate.com/restaurants/asbzWXaJjd",
"https://mp-seoul-image-production-s3.mangoplate.com/106666/694014_1561453641850_4592?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) {

startActivity(intent)

}
}
recyclerView.layoutManager=GridLayoutManager(this,2)

}
}

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

2021. 08. 25. 23:44

Activity, xml, adapter 부분의 코드를 모두 공유해주세요~

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

2021. 08. 25. 23:44

코드 일부가 아니라 전체 코드를 공유해주셔야 합니다~

0

dudah754님의 프로필 이미지
dudah754
질문자

2021. 08. 25. 19:38

1. RecyclerView 꾸며보기, 22초 부분

2. 작성한 코드

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kkk.mango_content">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Mango_content">
<activity
android:name=".ViewActivity"
android:exported="true" />
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true"></activity>
</application>

</manifest>

3.  리사이클뷰 모양은 뜨는데 사진이 로드 되지 않습니다

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

2021. 08. 24. 21:22

아래의 부분을 참고해주세요

Q. 온라인으로 학습하다 보면 막힐 때가 많은데 어떻게 해결할 수 있을까요?

강의 질문/답변을 남겨주세요. 질문을 주실 때 다음 정보를 꼭 함께 올려주세요! (강의에 사용한 소스코드를 모두 첨부했으나, 복사/붙여넣기로 진행해는데도 동작하지 않을 경우에도 꼭 다음 양식을 지켜서 진행해주세요.)

  1. 시청 중인 강의의 부분 (수업 제목 및 타임코드)
    2. 내가 작성한 코드
    3. 에러가 나온다면, 어떻게 나오는지 (에러 내용)
dudah754님의 프로필 이미지

작성한 질문수

질문하기