title: Life cycle of views created by getView method of BaseAdapter subclass
body: <p>I have a problem related with life cycle of views created by custom adapter for common <code>ListView</code>. I created  a custom view as follows:</p>
  
  <pre><code>    public class NSViewZoneLarge extends RelativeLayout
      {
          private long mZoneId;
          private ToggleButton mOnOffButton;
  
          public NSViewZoneLarge(Context context, boolean showSwitch, long zoneId)
          {
              super(context);
              LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              layoutInflater.inflate(R.layout.view_zone_large, this);
              mOnOffButton = (ToggleButton) findViewById(R.id.toggleButtonOnOff);
  
              ImageView imgView = (ImageView)findViewById(R.id.imageViewZoneType);
              imgView.setFocusable(false);
  
              if (showSwitch)
              {
                  mOnOffButton.setVisibility(View.VISIBLE);
              }
              else
              {
                  mOnOffButton.setVisibility(View.INVISIBLE);
                  mOnOffButton.setEnabled(false);
                  mOnOffButton.setFocusable(false);
                  mOnOffButton.setFocusableInTouchMode(false);
              }
  
              mZoneId = zoneId;
          }
  
          // ---------------------------------------------------------------------------------------
          public NSViewZoneLarge(Context context, AttributeSet attrs)
          {
              super(context, attrs);
          }
  
          // ---------------------------------------------------------------------------------------
          public void setZoneName(String zoneName)
          {
              TextView tVZoneName = (TextView) findViewById(R.id.textViewZoneName);
              tVZoneName.setText(zoneName);
          }
  
          // ---------------------------------------------------------------------------------------
          public String getZoneName()
          {
              TextView tVZoneName = (TextView) findViewById(R.id.textViewZoneName);
              return tVZoneName.getText().toString();
          }
  
          // ---------------------------------------------------------------------------------------
          public void setOnOffButton(boolean isOn)
          {
              ToggleButton onOffButton = (ToggleButton) findViewById(R.id.toggleButtonOnOff);
              onOffButton.setChecked(isOn);
          }
  
          // ---------------------------------------------------------------------------------------
          public boolean isOnOffButtonChecked()
          {
              ToggleButton onOffButton = (ToggleButton) findViewById(R.id.toggleButtonOnOff);
              return onOffButton.isChecked();
          }
  
          // ---------------------------------------------------------------------------------------
          public long getZoneId()
          {
              return mZoneId;
          }
  }
  </code></pre>
  
  <p>Then I instantiate this view in <code>getView()</code> method of my <code>BaseAdapter</code> subclass:</p>
  
  <pre><code>// ---------------------------------------------------------------------------------------
  @Override
  public View getView(int position, View convertView, ViewGroup parent)
  {
      NSDestinationContent destinationContent = mDestinationContents.get(position);
      NSViewZoneLarge viewZone = new NSViewZoneLarge(mContext, mShowSwitches, destinationContent.mDestinationContentId);
  
      viewZone.setZoneName(destinationContent.mName);
  
      if (mShowSwitches)
          viewZone.setOnOffButton(mOnOffStates.get(position));
  
      if (destinationContent.mDestinationTypeId.equals(DestinationTypeId.SPEAKERS_GROUP))
      {
          NSSpeakerGroup speakerGroup = (NSSpeakerGroup) destinationContent;
          viewZone.setZoneType(speakerGroup.mZoneTypeId);
      }
  
      return viewZone;
  }
  </code></pre>
  
  <p>Finally, I set <code>OnItemLongClickListener</code> for the <code>listView</code>:</p>
  
  <pre><code>    mZonesListView.setOnItemLongClickListener(new OnItemLongClickListener()
      {
          public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id)
          {
              NSViewZoneLarge viewZoneLarge = (NSViewZoneLarge)view;
              long destinationId = viewZoneLarge.getZoneId();
              ClipData data = ClipData.newPlainText(NSConstants.DRAG_KEY_ZONE_ID, String.valueOf(destinationId));
  
              view.startDrag(data, new DragShadowBuilder(view), null, 0);
  
              Intent intent = new TrashBinIntent(true);
              LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(ApplicationNetSpeaker.getInstance());
              localBroadcastManager.sendBroadcast(intent);
  
              return true;
          }
      });
  </code></pre>
  
  <p>The problem is that method <code>getZoneId()</code> returns always null although I set this value through the <code>NSViewZoneLarge</code> constructor in <code>getView()</code> method correctly. </p>
  
  <p>I know why it returns null; it is because <code>OnItemLongClickListener</code> gives me an instance of <code>NSViewZoneLarge</code> which is not the one created by <code>getView()</code> method. Somewhere, somehow the <code>NSViewZoneLarge</code> instance is created with the second – default constructor only.</p>
  
  <p>I also tried to use <code>setTag()</code> method to associate data with the view, but the <code>getTag()</code> method always returns null – again, the original instance is lost somewhere, probably released by GC, and I get a new instance with no tag set instead.</p>
  
  <p>Can somebody explain me why this occurs and how can I associate any kind of data with a particular view of <code>ListView</code> item?</p>