-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/example/appshortcut/AppListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |