title: How do you pass and update data to a Baseadapter in a Baseadapter
body: <p>I have a Listview that contains an spinner in it. I am using the baseadapter class to fill the listview and the spinner. How do I pass the Vector I have to each spinner in the Listview. The Vector for the spinner is the same for all the items in the listview. </p>
  
  <p>The workflow is the listview starts empty, but the vector for the spinner is populated and will not change.  Then the user will add image(s) to the listview and might select from the spinner adapter.</p>
  
  <p>The problem I am having is the Spinner never seems to get the data, it justs lists "Please Select" and each time I focus on the spinner it adds two more "Please Select" to it.</p>
  
  <p>I also need to know how to get the selected value of the spinner from the activity that is using the two adapters.</p>
  
  <p>Here is the <code>Baseadapter</code> for the <code>Listview</code>.</p>
  
  <pre><code>public class InvoicePicAdapter extends BaseAdapter {
  
   private Context context;
   private ArrayList&lt;InvoicePicItem&gt; invoicepics;
   private VectorItemsOnInvoice itemsOnInvoice;
  
   public InvoicePicAdapter(Context context, ArrayList&lt;InvoicePicItem&gt; invoicepics,VectorItemsOnInvoice items ){
       this.context=context;
       this.invoicepics=invoicepics;
       this.itemsOnInvoice=items;
   }
  
  @Override
  public int getCount() {
      return invoicepics.size();
  }
  
  @Override
  public InvoicePicItem getItem(int position) {
      return invoicepics.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  protected void deleteImage(int position) {
     this.invoicepics.remove(position);
  }
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = (View) inflater.inflate(
                  R.layout.listview_item_invoice_pic, null);
      }
  
      ImageView imgPartPic=(ImageView)convertView.findViewById(R.id.imgPart);
  
      imgPartPic.setTag(Integer.valueOf(position));
      imgPartPic.setOnLongClickListener(new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(final View v) { 
              AlertDialog.Builder builder = new AlertDialog.Builder(context);
              builder.setMessage("Delete this Picture?");
              builder.setCancelable(true);
              builder.setPositiveButton("Yes",
                      new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                      int position = (Integer) v.getTag();
                      deleteImage(position);
                      notifyDataSetChanged();
                      dialog.cancel();
                  }
              });
              builder.setNegativeButton("No",
                      new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                      dialog.cancel();
                  }
              });
  
              AlertDialog alert = builder.create();
              alert.show();
  
              return true;
              }
          });
  
      android.view.ViewGroup.LayoutParams layoutParams = imgPartPic.getLayoutParams();
      layoutParams.width = 400;
      layoutParams.height = 300;
      imgPartPic.setLayoutParams(layoutParams);
      imgPartPic.setScaleType(ScaleType.FIT_XY);
  
      imgPartPic.setImageBitmap(invoicepics.get(position).getImage());
  
      Spinner spinItemsOnInvoice = (Spinner)convertView.findViewById(R.id.spinnerItemsOnInvoice);
      InvoicePicSpinAdapter spinnerAdapter = new InvoicePicSpinAdapter(context,
              android.R.layout.simple_spinner_item,itemsOnInvoice);
      spinItemsOnInvoice.setAdapter(spinnerAdapter);
      return convertView;
  }
  }
  </code></pre>
  
  <p>Then this is the code for the Spinner BaseAdapter.</p>
  
  <pre><code>public class InvoicePicSpinAdapter extends ArrayAdapter&lt;ItemsOnInvoice&gt;{
  private VectorItemsOnInvoice values;
  private Context context;
  
  public InvoicePicSpinAdapter(Context context, int simpleSpinnerItem,
          VectorItemsOnInvoice response) {
      super(context, simpleSpinnerItem, response);
      ItemsOnInvoice pleaseSelect  = new ItemsOnInvoice();
      pleaseSelect.inventoryID=0;
      response.add(0, pleaseSelect);
      this.values= response;
      this.context = context;
  }
  
  public void updateItemsOnInvoice(VectorItemsOnInvoice items){
      ItemsOnInvoice pleaseSelect  = new ItemsOnInvoice();
      pleaseSelect.inventoryID=0;
      items.add(0, pleaseSelect);
      this.values= items;
  }
  
  public int getCount(){
     return values.size();
  }
  
  public ItemsOnInvoice getItem(int position){
     return values.elementAt(position);
  }
  
  public long getItemId(int position){
     return position;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      TextView label = new TextView(context);
      label.setTextColor(Color.BLACK);
  
      if (values.elementAt(position).inventoryID==0){
          label.setText("Please Select");
      } else {
          if (values.elementAt(position).isSPIG==0){
              label.setText("G"+String.valueOf(values.elementAt(position).groupNumber));
          } else {
              label.setText("R"+String.valueOf(values.elementAt(position).inventoryID));
          }
      }
      return label;
  }
  
  @Override
  public View getDropDownView(int position, View convertView,
          ViewGroup parent) {
      TextView label = new TextView(context);
  
      if (position==0){
          label.setTextColor(Color.GRAY);
          label.setTextSize(22);
          label.setText("Please Select");
      } else {
          label.setTextColor(Color.BLACK);
          label.setTextSize(28);
          if (values.elementAt(position).inventoryID==0){
              label.setText("Please Select");
          } else {
              if (values.elementAt(position).isSPIG==0){
                  label.setText("G"+String.valueOf(values.elementAt(position).groupNumber));
              } else {
                  label.setText("R"+String.valueOf(values.elementAt(position).inventoryID));
              }
          }
      }       
      return label;
  }
  }
  </code></pre>