소개
게시글
질문&답변
2021.08.26
사진이 안나와요
이렇게 올려드리면 될까요?? RVadpater package com.kkk.mango_contentimport android.content.Contextimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport android.widget.ImageViewimport android.widget.TextViewimport androidx.appcompat.view.menu.ActionMenuItemViewimport androidx.recyclerview.widget.RecyclerViewimport com.bumptech.glide.Glideclass RVAdapter (val context : Context, val List : MutableList) : RecyclerView.Adapter(){ 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(R.id.rvImageArea) val rv_text = itemView.findViewById(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"?>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" > android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="match_parent"/> MainActivity package com.kkk.mango_contentimport androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport android.view.Viewimport android.widget.GridLayoutimport androidx.recyclerview.widget.GridLayoutManagerimport androidx.recyclerview.widget.LinearLayoutManagerimport androidx.recyclerview.widget.RecyclerViewclass MainActivity : AppCompatActivity() { private val items = mutableListOf() 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(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
- 6
- 244
질문&답변
2021.08.25
사진이 안나와요
1. RecyclerView 꾸며보기, 22초 부분 2. 작성한 코드 xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android" package="com.kkk.mango_content"> android:name="android.permission.INTERNET" /> 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"> android:name=".ViewActivity" android:exported="true" /> android:name=".SplashActivity" android:exported="true"> android:name="android.intent.action.MAIN" /> android:name="android.intent.category.LAUNCHER" /> android:name=".MainActivity" android:exported="true"> 3. 리사이클뷰 모양은 뜨는데 사진이 로드 되지 않습니다
- 0
- 6
- 244