Skip to content

Commit

Permalink
added recyclerview adapter (#19)
Browse files Browse the repository at this point in the history
* feat: added coin data class

* feat: added a comment

* feat: added a comment

* added splash screen

* feat: added converter page ui

* feat: added rv adapter

Co-authored-by: Rohith Menon <[email protected]>
Co-authored-by: rudrankbasant <[email protected]>
Co-authored-by: Rudrank Basant <[email protected]>
  • Loading branch information
4 people authored Oct 25, 2022
1 parent ca655fc commit d431f65
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
10 changes: 4 additions & 6 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions app/src/main/java/com/example/coint/adapters/RVAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.coint.adapters

import android.content.Context
import android.provider.ContactsContract
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.coint.R
import com.example.coint.models.CoinData

class RVAdapter(
val context: Context
): RecyclerView.Adapter<RVAdapter.ViewHolder>(){

private val allEntries = ArrayList<CoinData>()
inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
val titleTV =itemView.findViewById<TextView>(R.id.tvCoinTitle)
val descTV= itemView.findViewById<TextView>(R.id.tvCoinDescription)
val valueTV =itemView.findViewById<TextView>(R.id.tvCoinValue)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_coin,parent,false)
return ViewHolder(itemView)

}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.titleTV.setText(allEntries.get(position).abbrev)
holder.descTV.setText(allEntries.get(position).full)
holder.valueTV.setText(allEntries.get(position).value.toString())

}

override fun getItemCount(): Int {
return allEntries.size
}

fun updateList(newList: List<CoinData>){
allEntries.clear()
allEntries.addAll(newList)
notifyDataSetChanged()
}
}

0 comments on commit d431f65

Please sign in to comment.