Skip to content

Commit

Permalink
Aula 216 - Listando Contatos - Parte 1
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloamsilva committed Aug 16, 2018
1 parent efc7de9 commit ca9ed97
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

import br.com.whatsappandroid.cursoandroid.whatsapp2.R;
import br.com.whatsappandroid.cursoandroid.whatsapp2.model.Contato;

/**
* A simple {@link Fragment} subclass.
*/
public class ContatosFragment extends Fragment {

private ListView listView;
private ArrayAdapter adapter;
private ArrayList<String> contatos;

public ContatosFragment() {
// Required empty public constructor
Expand All @@ -24,8 +32,25 @@ public ContatosFragment() {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

//Instânciar objetos
contatos = new ArrayList<>();
contatos.add("Mariana Silva");
contatos.add("Leticia Almeida");
contatos.add("José Renato");

// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_contatos, container, false);
View view = inflater.inflate(R.layout.fragment_contatos, container, false);

listView = view.findViewById(R.id.lv_contatos);
adapter = new ArrayAdapter(
getActivity(),
R.layout.lista_contato,
contatos
);
listView.setAdapter(adapter);

return view;
}

}
12 changes: 5 additions & 7 deletions app/src/main/res/layout/fragment_contatos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
tools:context=".fragment.ContatosFragment">

<!-- TODO: Update blank fragment layout -->
Expand All @@ -12,19 +13,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ListView
android:id="@+id/lv_contatos"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Contatos"
android:textColor="@android:color/black"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/lista_contato.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="@android:color/black"
android:textSize="16sp"
android:padding="8dp"
android:text="Nome"
/>

0 comments on commit ca9ed97

Please sign in to comment.