Android | Getting wrong Position through ListView
<p>I m having problem with getiing tag in onclick Listener</p>

<pre><code>@Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        Log.v("Tag", "Testing inflating getView");
        TextView tv = null;


        if (items != null) {
            StoreVirtualItem vi = (StoreVirtualItem) items.get(position);
            Log.i("testing", vi.getName()+",position ="+ position);
            if (vi != null) {
                if (convertView == null) 
                {
                    convertView = (RelativeLayout) View.inflate(context, context.getResources().getIdentifier("virtualitemrow", "layout", context.getPackageName()), null);
                    holder = new ViewHolder();
                    holder.textView = (TextView) convertView.findViewById(R.id.virtualItemDescription);
                    holder.layout = (RelativeLayout) convertView.findViewById(R.id.LinearLayout01);
                    holder.virtualItemIconLayout = (RelativeLayout) convertView.findViewById(R.id.LinearLayout02);
                    holder.newImage = (ImageView) convertView.findViewById(R.id.newimage);
                    holder.iconImage=null;
                    ((ImageView)holder.virtualItemIconLayout.findViewById(R.id.iconImage)).setImageBitmap(null);
                    ((ImageView)holder.virtualItemIconLayout.findViewById(R.id.backGroundThumbImage)).setImageBitmap(null);
                    if(!vi.getStoreName().equalsIgnoreCase( FishGameConstants.BACKGROUNDS_STORE_NAME)){
                        holder.iconImage = (ImageView)holder.virtualItemIconLayout.findViewById(R.id.iconImage);
                    }else{
                        holder.iconImage = (ImageView)holder.virtualItemIconLayout.findViewById(R.id.backGroundThumbImage);
                    }
                    holder.saleImage = (ImageView) convertView.findViewById(R.id.saleimage);
                    int progressBarId = 2;
                    holder.iconSpinner = (ProgressBar) holder.virtualItemIconLayout.findViewById(progressBarId);
                    holder.buyBtn = (Button) convertView.findViewById(R.id.Button01);
                    holder.soldOutImage = (ImageView) convertView.findViewById(R.id.ImageView01);
                    holder.lockView = (ImageView) convertView.findViewById(R.id.ImageView03);
                    holder.levelRequiredText = (TextView) convertView.findViewById(R.id.LevelRequiredText);
                    holder.offerLetTime = (TextView) convertView.findViewById(R.id.TextView07);
                    holder.currencyImage = (ImageView) convertView.findViewById(R.id.ImageView02);
                    holder.vgName = (TextView) convertView.findViewById(R.id.TextView01);
                    holder.line = (TextView)  convertView.findViewById(R.id.line);
                    holder.coinsText = (TextView)  convertView.findViewById(R.id.text);
                    holder.saleBuyPriceText = (TextView) convertView.findViewById(R.id.TextView06);
                    holder.previewBtn = (Button) convertView.findViewById(R.id.PreviewBtn);
                    holder.sellText = (TextView) convertView.findViewById(R.id.TextView03);
                    holder.adultText = (TextView) convertView.findViewById(R.id.TextView04);
                    holder.breedableText = (TextView) convertView.findViewById(R.id.TextView05);
                    holder. infoBtutton = (ImageView) convertView.findViewById(R.id.infoButton);
                    holder. reStockText = (TextView) convertView.findViewById(R.id.restockText);
                    holder.reStockText1 =(TextView)  convertView.findViewById(R.id.LinearLayout01).findViewById(1234567890);
                    ViewFactory.getInstance().scaleView(convertView);
                    convertView.setTag(holder);
                    holder.buyBtn.setTag("buy,"+position);
                    Log.i("testing", "if buy position1 ="+ position);
                }else {

                    holder = (ViewHolder) convertView.getTag();
                    holder.buyBtn.setTag("buy,"+position);
                    Log.i("testing", "else buy position1 ="+ position);
                }
</code></pre>

<p>Above mentioned code set position as a tag on BuyBtn in both if and else but upon getting it on its click listener it returns last row position of list view currently populated i-e, I clicked on 0th position of list view and it returned me 2nd position. On more concern is that after scrolling it gets alright.</p>

<p>Below is onclick listner where i am getting position.</p>

<pre><code>@Override
            public void onClick(View v) {
                Log.i("clicked", ""+v.getTag());
                TransparentDialog.getInstance(context).show();
            if(category.getStoreName().equalsIgnoreCase(TapFishConstant.FISHEGGS_STORE_NAME)){
                TapFishConfig.getInstance(null).setCategoryModel(category);
            }
            v.setClickable(false);
            if(virtualItemListview != null){                    
                virtualItemListview.setClickable(false);
                virtualItemListview.setEnabled(false);
            }
            int position = -1;
            if (VgItemHashMap.containsKey(v)) {
                position = (Integer) VgItemHashMap.get(v);
                TapFishConfig.getInstance(null).lastSelectedListViewItem=position;
                if (storeListener != null) {
                    String action = v.getTag().toString().split(",")[0];
                    int itemPosition = Integer.parseInt(v.getTag().toString().split(",")[1]);
                    StoreVirtualItem vi = (StoreVirtualItem) items.get(itemPosition);
</code></pre>

<p>Both above mentioned codes are written in same adapter.</p>
