title: Using ListView, remove in Adapter always removes the last item
body: <p>I have a ListView in my Activity with a custom Adapter.</p>
  
  <p>Every item has a delete button on it. When someone clicks on the button, a dialog pops up asking if the user really wants to delete the item, upon clicking on yes, the item gets deleted.</p>
  
  <p>I verified that internally the right items gets removed, but visually only the last item from the list gets removes. Activity.recreate shows that the right item got deleted, but I don't want to call recreate when a simple remove and notifyDataSetChanged() could do the trick.</p>
  
  <p>Can someone point me into the right direction as to what could be wrong with my code?</p>
  
  <p>the source code in my activity is:</p>
  
  <pre><code>        ListView mylistview = (ListView) findViewById(R.id.listFriends);
          SS4ListItemFriendsAdapter adapter = new SS4ListItemFriendsAdapter(getApplicationContext(), SS4NewGameActivity.this, SS4ListItemFriendsRows);
            mylistview.setAdapter(adapter);
  </code></pre>
  
  <p>This is my Adapter:</p>
  
  <pre><code>public class SS4ListItemFriendsAdapter extends BaseAdapter {
  
   Context context;
   List&lt;SS4ListItemFriendsRow&gt; rowItems;
   private Activity activity;
  
  
    SS4ListItemFriendsAdapter(Context context, Activity act, List&lt;SS4ListItemFriendsRow&gt; rowItems) {
  
    this.context = context;
    this.rowItems = rowItems;
    this.activity = act;
  
   }
  
   @Override
   public int getCount() {
    return rowItems.size();
   }
  
   @Override
   public Object getItem(int position) {
    return rowItems.get(position);
   }
  
   @Override
   public long getItemId(int position) {
    return rowItems.indexOf(getItem(position));
   }
  
   /* private view holder class */
   private class ViewHolder {
    ImageView avatar;
    ImageView delete;
    TextView username;
   }
  
   @Override
   public View getView(final int position, View convertView, ViewGroup parent) {
  
    ViewHolder holder = null;
  
    LayoutInflater mInflater = (LayoutInflater) context
      .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
     convertView = mInflater.inflate(R.layout.ss4_list_item_friends, null);
     holder = new ViewHolder();
  
     holder.username = (TextView) convertView
       .findViewById(R.id.username);
     holder.avatar = (ImageView) convertView
       .findViewById(R.id.avatar);
  
     holder.delete = (ImageView) convertView
               .findViewById(R.id.delete);
  
     if (getCount() &gt; 0) {       
         if (((SS4ListItemFriendsRow) getItem(0)).getDelete() == 0) {    
             holder.delete.setVisibility(ImageView.INVISIBLE);
         }
     }
  
     final SS4ListItemFriendsRow row_pos = rowItems.get(position);
  
     holder.avatar.setImageResource(row_pos.getAvatar());
     holder.username.setText(row_pos.getUsername());
  
     holder.delete.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             Sounds.buttonClick();
             Log.d(App.TAG, row_pos.getUsername());
  
             deleteFriendDialogBox(row_pos.getUsername(), position);             
         }
     });   
  
     convertView.setTag(holder);
    } else {
     holder = (ViewHolder) convertView.getTag();
    }
  
    return convertView;
   }
  
   private void deleteFriendDialogBox(final String username, final int position)
   {
  
      //String title = "deleteFriend?";
      String msg = context.getResources().getString(R.string.ss4_delete_friend);
  
       AlertDialog myQuittingDialogBox =  new AlertDialog.Builder(activity) 
  
           .setCancelable(false)
           .setTitle("")
           .setMessage(msg) 
  
  
           .setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
               public void onClick(DialogInterface dialog, int whichButton) { 
  
                      rowItems.remove(position); 
                      Log.d(App.TAG,"position: "+String.valueOf(position));
  
                      notifyDataSetChanged();                         
                      SS4NewGameActivity.getListViewSize(mylistview);                     
  
                      //activity.recreate();
                      try {
                          int showMsgBox = (Integer) friend.getInt("showMsgBox");
                          if (showMsgBox == 1) {
                              String msg = (String) friend.getString("msg");
                              Toast.makeText(context, msg,Toast.LENGTH_LONG).show();
                          }                   
                      } catch (JSONException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
  
                      Sounds.buttonClick();
  
               }              
           })//setPositiveButton
  
           .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
               public void onClick(DialogInterface dialog, int whichButton) {
                  Sounds.buttonClick();
  
  
            } 
           })//setNegativeButton
  
           .create();
  
       myQuittingDialogBox.show();
   }    
  
  }
  </code></pre>