Skip to content

Commit

Permalink
Add recylcerView
Browse files Browse the repository at this point in the history
  • Loading branch information
yonce3 committed Apr 15, 2021
1 parent 07d4ec0 commit 2ca8226
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/src/main/java/com/example/appshortcut/AppListAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.appshortcut

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

class AppListAdapter(private val appList: List<AppInfo>): RecyclerView.Adapter<AppListAdapter.AppListViewHolder>() {

inner class AppListViewHolder(view: View): RecyclerView.ViewHolder(view) {
val appIcon: ImageView = view.findViewById(R.id.app_icon)
val appLabel: TextView = view.findViewById(R.id.app_label)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppListViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.app_list_item, parent, false)

return AppListViewHolder(view)
}

override fun onBindViewHolder(holder: AppListViewHolder, position: Int) {
holder.appLabel.text = appList[position].appLabel
holder.appIcon.setImageDrawable(appList[position].appIcon)
}

override fun getItemCount(): Int = appList.size
}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/app_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView
android:id="@+id/app_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/app_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/app_icon"
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 2ca8226

Please sign in to comment.