Advertisement
Guest User

ListaAlunosAdapter.java

a guest
Mar 26th, 2021
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. public class ListaAlunosAdapter extends BaseAdapter {
  2.     private final List<Aluno> alunos = new ArrayList<>();
  3.     private Context contexto;
  4.  
  5.     public ListaAlunosAdapter(Context contexto) {
  6.         this.contexto = contexto;
  7.     }
  8.  
  9.  
  10.     @Override
  11.     public int getCount() {
  12.         int size = alunos.size();
  13.         return size;
  14.     }
  15.  
  16.     @Override
  17.     public Aluno getItem(int position) {
  18.         return alunos.get(position);
  19.     }
  20.  
  21.     @Override
  22.     public long getItemId(int position) {
  23.         return alunos.get(position).getId();
  24.     }
  25.  
  26.     @Override
  27.     public View getView(int position, View convertView, ViewGroup groupp) {
  28.         View layout = LayoutInflater.from(this.contexto).inflate(R.layout.item_aluno,groupp, false);
  29.         Aluno aluno = alunos.get(position);
  30.         TextView tvn = layout.findViewById(R.id.item_aluno_nome);
  31.         TextView tvt = layout.findViewById(R.id.item_aluno_telefone);
  32.         tvn.setText(aluno.getNome());
  33.         tvt.setText(aluno.getTelefone());
  34.  
  35.         return layout;
  36.     }
  37.  
  38.     public void clear() {
  39.         alunos.clear();
  40.         notifyDataSetChanged();
  41.     }
  42.  
  43.     public void addAll(List<Aluno> alunos) {
  44.         alunos.addAll(alunos);
  45.         notifyDataSetChanged();
  46.     }
  47.  
  48.     public void remove(Aluno a) {
  49.         alunos.remove(a);
  50.         notifyDataSetChanged();
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement