I am trying to delete a row when the user clicks on the button to delete. The issue that I am facing is that if I delete any row it removes the last row on UI. I have an adapter with the Arraylist. On click I remove the the item from the arraylist and call notifydatasetchanged . On debugging I am seeing that correct item has been deleted yet on UI I see that last row is not seen (the deleted row can still be seen)
public class MenuDetailsAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<MenuItem> menuItems;
private View userView,itemView ;
public MenuDetailsAdapter(Activity activity, List<MenuItem> menuItems) {
this.activity=activity;
this.menuItems = menuItems;
}
@Override
public int getCount() {
return menuItems.size();
}
@Override
public Object getItem(int pos) {
return menuItems.get(pos);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (inflater == null) {
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if(convertView==null)
{
convertView= inflater.inflate(R.layout.menu_card_row, null);
ImageView im= (ImageView) convertView.findViewById(R.id.btnRemoveItemRow);
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
menuItems.remove(position);
notifyDataSetChanged();
}
});
TextView tvItemName=(TextView) convertView.findViewById(R.id.tvItem_name);
tvItemName.setText(((MenuItem) getItem(position)).getName());
TextView tvItemPrice=(TextView) convertView.findViewById(R.id.tvItemPrice);
tvItemPrice.setText(tvItemPrice.getText().toString()+ ((MenuItem) getItem(position)).getCost());
TextView tvItemQty=(TextView) convertView.findViewById(R.id.tvItem_qty);
tvItemQty.setText(tvItemQty.getText().toString()+ ((MenuItem) getItem(position)).getQuanity());
}
return convertView;
}
}