Created
September 5, 2018 12:34
-
-
Save brunoazevedomendonca/e3db927c313b1450475a13a244ae0174 to your computer and use it in GitHub Desktop.
Adapter simples para Strings em RecyclerView
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="64dp" | |
android:id="@+id/container"> | |
<TextView | |
android:id="@+id/tvNome" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center_vertical" | |
android:textSize="20sp" | |
android:layout_marginLeft="16dp" | |
android:layout_marginRight="16dp" | |
android:text="Nome"/> | |
</LinearLayout> |
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
package br.com.brunoazevedo.contatinhos | |
import android.content.Context | |
import android.support.v7.widget.RecyclerView | |
import android.view.View | |
import android.view.ViewGroup | |
import android.view.LayoutInflater | |
import kotlinx.android.synthetic.main.contatinho_item_lista.view.* | |
class ContatinhoAdapter(val contatinhos: List<String>) | |
: RecyclerView.Adapter<ContatinhoAdapter.ViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val view = LayoutInflater.from(parent.context).inflate(R.layout.contatinho_item_lista, parent, false) | |
return ViewHolder(view) | |
} | |
override fun getItemCount(): Int { | |
return contatinhos.size | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.bindView(contatinhos[position]) | |
} | |
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun bindView(contatinhoNome: String) { | |
itemView.tvNome.text = contatinhoNome | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment