GeorgePashev_88

Contacts Custom Array Adapter

Apr 23rd, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | Source Code | 0 0
  1.  public class CustomArrayAdapter extends ArrayAdapter<Contacts>{
  2.         private Context context;
  3.         private int resource;
  4.  
  5.  
  6.         public CustomArrayAdapter(@NonNull Context context, int resource, @NonNull List<Contacts> objects) {
  7.             super(context, resource, objects);
  8.             this.context = context;
  9.             this.resource = resource;
  10.         }
  11.         @Override
  12.         public View getView(int position, View convertView, ViewGroup parent){
  13.             Contacts contacts = getItem(position);
  14.  
  15.             if(convertView == null){
  16.                 convertView = LayoutInflater.from(context).inflate(resource,
  17.                         parent, false);
  18.             }
  19.             TextView viewID =convertView.findViewById(R.id.listViewID);
  20.             viewID.setText(contacts.getID());
  21.             TextView viewName =convertView.findViewById(R.id.listViewName);
  22.             viewName.setText(contacts.getName());
  23.             TextView viewAddress =convertView.findViewById(R.id.listViewAddress);
  24.             viewAddress.setText(contacts.getAddress());
  25.             TextView viewPhone =convertView.findViewById(R.id.listViewPhone);
  26.             viewPhone.setText(contacts.getPhone());
  27.             TextView viewEmail =convertView.findViewById(R.id.listViewEmail);
  28.             viewEmail.setText(contacts.getEmail());
  29.             return  convertView;
  30.  
  31.         }
  32.  
  33.     }
Add Comment
Please, Sign In to add comment