TeguhSobari

Contact Adapter

Jun 19th, 2016
2,496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1.  
  2. import android.content.Context;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.TextView;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. public class ContactAdapter extends ArrayAdapter {
  13.  
  14.     List list = new ArrayList();
  15.     public ContactAdapter(Context context, int resource) {
  16.         super(context, resource);
  17.     }
  18.  
  19.     @Override
  20.     public void add(Object object)
  21.     {
  22.         super.add(object);
  23.         list.add(object);
  24.     }
  25.  
  26.     @Override
  27.     public int getCount()
  28.     {
  29.         return list.size();
  30.     }
  31.  
  32.     @Override
  33.     public Object getItem(int position)
  34.     {
  35.         return list.get(position);
  36.     }
  37.  
  38.     @Override
  39.     public View getView(int position, View convertView, ViewGroup parent) {
  40.         View row;
  41.         row = convertView;
  42.         ContactsHolder contactsHolder;
  43.         if (row == null)
  44.         {
  45.             LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  46.             row = layoutInflater.inflate(R.layout.list_item,parent,false);
  47.             contactsHolder = new ContactsHolder();
  48.             contactsHolder.tx_kode =(TextView) row.findViewById(R.id.tx_name);
  49.             contactsHolder.tx_nama =(TextView) row.findViewById(R.id.tx_brg);
  50.             contactsHolder.tx_harga =(TextView) row.findViewById(R.id.tx_harga);
  51.             row.setTag(contactsHolder);
  52.  
  53.         }
  54.         else
  55.         {
  56.             contactsHolder = (ContactsHolder)row.getTag();
  57.  
  58.         }
  59.         Contacts contacts = (Contacts)this.getItem(position);
  60.         contactsHolder.tx_kode.setText(contacts.getKode());
  61.         contactsHolder.tx_nama.setText(contacts.getNama());
  62.         contactsHolder.tx_harga.setText(contacts.getHarga());
  63.         return row;
  64.     }
  65.     static class ContactsHolder
  66.     {
  67.         TextView tx_kode, tx_nama,tx_harga;
  68.     }
  69. }
Add Comment
Please, Sign In to add comment