-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aula 222 - Criando listagem de contatos customizada
- Loading branch information
1 parent
327f374
commit be40fe6
Showing
3 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
app/src/main/java/br/com/whatsappandroid/cursoandroid/whatsapp2/adapter/ContatoAdapter.java
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,54 @@ | ||
package br.com.whatsappandroid.cursoandroid.whatsapp2.adapter; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.TextView; | ||
|
||
import java.util.ArrayList; | ||
|
||
import br.com.whatsappandroid.cursoandroid.whatsapp2.R; | ||
import br.com.whatsappandroid.cursoandroid.whatsapp2.model.Contato; | ||
|
||
public class ContatoAdapter extends ArrayAdapter<Contato> { | ||
|
||
private ArrayList<Contato> contatos; | ||
private Context context; | ||
|
||
public ContatoAdapter(Context c, ArrayList<Contato> objects) { | ||
super(c, 0, objects); | ||
this.contatos = objects; | ||
this.context = c; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
|
||
View view = null; | ||
|
||
// Verifica se a lista está vazia | ||
if( contatos != null ){ | ||
|
||
// inicializar objeto para montagem da view | ||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); | ||
|
||
// Monta view a partir do xml | ||
view = inflater.inflate(R.layout.lista_contato, parent, false); | ||
|
||
// recupera elemento para exibição | ||
TextView nomeContato = view.findViewById(R.id.tv_nome); | ||
TextView emailContato = view.findViewById(R.id.tv_email); | ||
|
||
Contato contato = contatos.get( position ); | ||
nomeContato.setText( contato.getNome()); | ||
emailContato.setText( contato.getEmail() ); | ||
|
||
} | ||
|
||
return view; | ||
|
||
} | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<TextView | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_height="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" | ||
android:padding="8dp" | ||
android:text="Nome" | ||
/> | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/tv_nome" | ||
android:layout_height="wrap_content" | ||
android:layout_width="match_parent" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" | ||
android:paddingLeft="8dp" | ||
android:paddingRight="8dp" | ||
android:paddingTop="8dp" | ||
android:text="Nome do Contato" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/tv_email" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textColor="@android:color/black" | ||
android:textSize="14sp" | ||
android:paddingLeft="8dp" | ||
android:paddingRight="8dp" | ||
android:text="contato@email.com.br"/> | ||
|
||
</LinearLayout> |