daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Aug 15th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class DataAdapter extends BaseAdapter {
  2.  
  3.     private List<Data> dataList;
  4.     private Context context;
  5.  
  6.     public DataAdapter(Context context, List<Data> dataList) {
  7.         this.context = context;
  8.         this.dataList = dataList;
  9.     }
  10.  
  11.     public void addData(List<Data> newDataList) {
  12.         if (dataList == null)
  13.             dataList = new ArrayList<Data>();
  14.  
  15.         dataList.addAll(newDataList);
  16.         notifyDataSetChanged();
  17.     }
  18.  
  19.     @Override
  20.     public int getCount() {
  21.         return (dataList != null ? dataList.size() : 0);
  22.     }
  23.  
  24.     @Override
  25.     public Object getItem(int position) {
  26.         return dataList.get(position);
  27.     }
  28.  
  29.     static class ViewHolder {
  30.         public TextView nameTextView;
  31.     }
  32.  
  33.     @Override
  34.     public View getView(int position, View convertView, ViewGroup parent) {
  35.         final DataAdapter.ViewHolder holder;
  36.  
  37.         if (convertView == null) {
  38.             holder = new DataAdapter.ViewHolder();
  39.  
  40.             LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  41.             convertView = inflater.inflate(R.layout.list_item, parent, false);
  42.             holder.nameTextView = (TextView) convertView.findViewById(R.id.txt_name);
  43.  
  44.             convertView.setTag(holder);
  45.  
  46.         } else {
  47.             holder = (DataAdapter.ViewHolder) convertView.getTag();
  48.         }
  49.  
  50.         final Data data = dataList.get(position);
  51.         if (data != null) {
  52.         //set text
  53.         }
  54.  
  55.         }
  56.  
  57.         return convertView;
  58.     }
  59.  
  60.  
  61.     @Override
  62.     public int getViewTypeCount() {
  63.         return 0;
  64.     }
  65.  
  66.     @Override
  67.     public int getItemViewType(int position) {
  68.         return position;
  69.     }
  70.  
  71.     @Override
  72.     public long getItemId(int position) {
  73.         return position;
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top