inflearn logo
강의

講義

知識共有

【超初心者編】8つのアプリを作りながら学ぶAndroid Kotlin(アンドロイド・コトリン)

RecyclerView を飾ってみる

사진이 안나와요

320

dudah754

投稿した質問数 3

0

메니페스트.xml에 

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



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

android kotlin firebase

回答 6

0

bokchi

rv_item.xml

ContentsModel.kt

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

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

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

0

dudah754

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

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

bokchi

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

0

bokchi

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

0

dudah754

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

bokchi

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

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

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

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

주사위앱 소개 및 레이아웃 설정 문제

0

59

2

안드로이드 에뮬레이터가 실행이 안 되요...ㅠ

0

105

2

30 강 소스 좀 올려 주십시요

0

80

2

onBackPressed 함수가 동영상 하고 다르게 동작합니다.

0

89

2

ListView 초기 실행 안됩니다.

0

95

2

코딩을 완료하고난후 앱 실행시 자동 종료

0

71

2

datavinding에서 오류가 납니다.

0

51

1

안드로이드 스튜디오 버전 차이로 초기 empyt activity 선택하면 안됩니다.

0

109

2

context의 구별에 대하여

0

69

2

"프롤로그에서 ..." 오류 관련해 직전 질문에 대한 추가 질문입니다.

0

67

2

"프롤로그에서 콘텐츠가 허용되지 않습니다." 오류

0

156

3

해결완료

1

186

2

databinding 설정후 run하면 에러(해결)

0

222

2

databinding 설정 이후 실행시 에러

0

268

4

안드로이드 입문하는 사람입니다.

0

70

1

Firebase uid

0

76

3

activity_main 화면 다름

0

114

2

강의화면과 다른데 맞게진행되는것인가요...????

0

105

2

파이어베이스 질문

0

74

2

ActivityMainBinding에 오류가 납니다

0

134

2

선생님 onBackPressed 작동이 안되는거 같습니다

0

118

2

>app>res>layout 이 존재하지 않습니다.

0

119

2

안드로이드 스튜디오 미어캣 버전 사용 한글 깨짐

0

747

2

안드로이드 스튜디오 오류 발생 시 대처 방법은 요?

0

289

2