parent
519439785e
commit
8aa241e9b4
@ -0,0 +1,54 @@
|
||||
package com.example.shakecraft.view.adapter
|
||||
|
||||
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
|
||||
|
||||
import com.example.shakecraft.R
|
||||
import com.example.shakecraft.model.Item
|
||||
|
||||
|
||||
class AdapterBossLoot(private val possibleLoot: List<Pair<Item, Double>>) : RecyclerView.Adapter<AdapterBossLoot.ViewHolder>() {
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val textView: TextView
|
||||
val textViewDropRate: TextView
|
||||
var imageView: ImageView
|
||||
|
||||
|
||||
init {
|
||||
// Define click listener for the ViewHolder's View
|
||||
|
||||
textView = view.findViewById(R.id.item_name)
|
||||
textViewDropRate = view.findViewById(R.id.item_stock)
|
||||
imageView = view.findViewById(R.id.item_image)
|
||||
}
|
||||
fun bind(item: Pair<Item, Double>) {
|
||||
textView.text = item.first.name
|
||||
textViewDropRate.text = (item.second*100).toString() + "%"
|
||||
imageView.setImageResource(item.first.image)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = possibleLoot.size
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.list_loot, parent, false)
|
||||
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||
val item : Pair<Item, Double> = possibleLoot[position]
|
||||
viewHolder.bind(item)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:contentDescription="image of item"
|
||||
android:background="@drawable/item_background"
|
||||
android:id="@+id/item_image"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
app:srcCompat="@drawable/ic_key" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_name"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_stock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/grey_300"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in new issue