Wednesday, 18 May 2016

BaseAdaptor Example Android


 */public class ProfessionalListAdaptor extends BaseAdapter {

    List<ProfessionalResultModel> prList;
    Context mContext;
    ViewHolderItem viewHolder;

    public ProfessionalListAdaptor(Context context, List<ProfessionalResultModel> aList) {
        this.prList = aList;
        this.mContext = context;
    }

    @Override    
     public int getCount() {
        return prList.size();
    }

    @Override   
      public Object getItem(int position) {
        return prList.get(position);
    }

    @Override   
     public long getItemId(int position) {

        return position;
    }

    @Override    
    public View getView(final int position, View convertView, ViewGroup parent)
    {

        if (convertView == null) {
            viewHolder = new ViewHolderItem();
            LayoutInflater vi = (LayoutInflater) mContext
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(R.layout.professional_profile_list_item, null);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolderItem) convertView.getTag();
        }

   
         viewHolder.txtName = (TextView) convertView
                .findViewById(R.id.txtName);
    

      viewHolder.txtName.setText(list.getFirst_name() + " " + list.getLast_name());
     

        return convertView;
    }
   

static class ViewHolderItem {

    TextView txtName;
}
}

No comments:

Post a Comment