Created
March 21, 2018 01:02
-
-
Save cdmunoz/37b4a6a3ee75c387f1c00ae84712c63a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class CryptocurrenciesAdapter( | |
cryptocurrencies: List<Cryptocurrency>?) : RecyclerView.Adapter<CryptocurrencieViewHolder>() { | |
private var cryptocurrenciesList = ArrayList<Cryptocurrency>() | |
init { | |
this.cryptocurrenciesList = cryptocurrencies as ArrayList<Cryptocurrency> | |
} | |
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): CryptocurrencieViewHolder { | |
val itemView = LayoutInflater.from(parent?.context).inflate(R.layout.cryptocurrency_list_item, | |
parent, false) | |
return CryptocurrencieViewHolder(itemView) | |
} | |
override fun getItemCount(): Int { | |
return cryptocurrenciesList.size | |
} | |
override fun onBindViewHolder(holder: CryptocurrencieViewHolder?, position: Int) { | |
val cryptocurrencyItem = cryptocurrenciesList[position] | |
holder?.cryptocurrencyListItem(cryptocurrencyItem) | |
} | |
fun addCryptocurrencies(cryptocurrencies: List<Cryptocurrency>){ | |
val initPosition = cryptocurrenciesList.size | |
cryptocurrenciesList.addAll(cryptocurrencies) | |
notifyItemRangeInserted(initPosition, cryptocurrenciesList.size) | |
} | |
class CryptocurrencieViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
var cryptocurrencyId = itemView.findViewById<TextView>(R.id.cryptocurrency_id) | |
fun cryptocurrencyListItem(cryptocurrencyItem: Cryptocurrency) { | |
cryptocurrencyId.text = cryptocurrencyItem.id | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment