title: Why my listview Delete always last view from list
body: <p>I am adding Values to array and adapter and when i delete the specific item form listview it delete from arraylist perfectly but its delete the last view its mean if i have </p>
  
  <pre><code>a
  b
  c
  d
  e
  </code></pre>
  
  <p>when i delete b ....the e view is gones why...then the list is </p>
  
  <pre><code>a
  b
  c
  d
  </code></pre>
  
  <p>I worked on this from last 2 week but i cannot find the error in this help me.
  Please
  Please
  Please
  Please</p>
  
  <pre><code>public class Home extends AppCompatActivity {
  
      Button addMoreBtn,checkoutBtn;
      MedicineBean medicineBean;
      //CustomAdapter customAdapter;
      ArrayList&lt;MedicineBean&gt; medOrderList;
      //&lt;MedicineBean&gt; medOrderList1;
      MyDBHandler db;
      ListView listView;
      int cust_id;
      EditText med_nameET, med_potencyET, med_qtyET;
      ImageButton increaseQty,decreaseQty;
      HomeListViewHandler homeListViewHandler;
      private ArrayAdapter&lt;MedicineBean&gt; adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_home);
          String session_exp = SessionUtil.getSessionExpire(Home.this);
          if(Constants.LOGGING)
              Toast.makeText(getApplicationContext(),"Session Exp = "+session_exp+" Today Date "+new DateAndTimeUtil().getCurrentDate(),Toast.LENGTH_LONG).show();
  
          //30 days session expire checker
          if(session_exp.matches(new DateAndTimeUtil().getCurrentDate())){
              SessionUtil.setSignout(Home.this);
              Toast.makeText(getApplicationContext(),"Session has been expired due to 30 days limit exceeded",Toast.LENGTH_LONG).show();
              Intent intent = new Intent(Home.this, SignIn.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
              startActivity(intent);
          }
          //first check, Is user LOGGED IN  or not
          else if(SessionUtil.isLoggedIn(Home.this)) {
  
              Toolbar toolBar = (Toolbar) findViewById(R.id.easymed_toolbar);
              setSupportActionBar(toolBar);
              toolBar.setTitle(getResources().getString(R.string.home));
              DrawerUtil.getDrawer(this, toolBar);
  
              addMoreBtn      = (Button) findViewById(R.id.addtoList);
              checkoutBtn     = (Button) findViewById(R.id.checkOutBtn);
              listView        = (ListView) findViewById(R.id.medListView);
              med_nameET      = (EditText) findViewById(R.id.frstSingleItemET);
              med_potencyET   = (EditText) findViewById(R.id.scndSingleItemET);
              med_qtyET       = (EditText) findViewById(R.id.thrdSingleItemTV);
              increaseQty=(ImageButton) findViewById(R.id.increaceImgBtn);
              decreaseQty=(ImageButton) findViewById(R.id.decreaseImgBtn) ;
              medOrderList    = new ArrayList&lt;MedicineBean&gt;();
              //medOrderList1    = new ArrayList&lt;MedicineBean&gt;();
              cust_id         = SessionUtil.getCustomerId(Home.this);
              medicineBean    = new MedicineBean();
              db              = new MyDBHandler(Home.this);
              //customAdapter   = new CustomAdapter();
              adapter=new CustomAdapter(this,0,medOrderList);
              listView.setAdapter(adapter);
  
  
              increaseQty.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      if(Constants.LOGGING)
                          System.out.println("Increment Btn pressed");
                      int val = Integer.parseInt(med_qtyET  .getText().toString());
                      val=val+1;
                      String str = Integer.toString(val);
                      med_qtyET  .setText(str);
  
                  }
              });
  
             decreaseQty.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      int val = Integer.parseInt(med_qtyET  .getText().toString());
                      if(val&gt;0) {
                          val = val-1;
                          String str = Integer.toString(val);
                          med_qtyET.setText(str);
                      }
  
                  }
              });
              checkoutBtn.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      //add new medicines in local DB
                      int count = 0;
  
                      for (int i = 0; i &lt; medOrderList.size(); i++) {
  
                          String name             = medOrderList.get(i).getMediceneName();
                          String potency=medOrderList.get(i).getMedicenePotency();
                          String qty = medOrderList.get(i).getMediceneQty();
  
                          if (!name.matches("") &amp;&amp; !potency.matches("") &amp;&amp; !qty.matches("")) {
  
                              //Check if medicine with same potency available in DB then quantity of medicine add
                              Cursor cursor = db.getMedByNameAndPotency(cust_id,name,potency);
                              if(cursor.getCount()&gt;0)
                              {
                                  cursor.moveToNext();
                                  String qtyInDB      = cursor.getString(0);
                                  int qtyInDBInt      = Integer.parseInt(qtyInDB);
                                  int getQtyFromET    = Integer.parseInt(qtyInDB);
                                  int resultOfSumQty  = getQtyFromET  +   qtyInDBInt;
                                  db.updateMedQTY(cust_id,name,potency,resultOfSumQty);
                              }
                              //add new medicine
                              else if (db.addUsersMed(cust_id, name, potency, qty) != -1) {
                                  medicineBean.setCust_id(cust_id);
                                  medicineBean.setMediceneName(name);
                                  medicineBean.setMedicenePotency(potency);
                                  medicineBean.setMediceneQty(qty);
                                  medOrderList.set(i, medicineBean);
                                  //Log.i(Constants.TAG,medOrderList.get(i).toString());
                                  count++;
                              }
                          }
  
                      }
                      if (count &gt; 0) {
                          Toast.makeText(getApplicationContext(), "Medicines added successfully.", Toast.LENGTH_SHORT).show();
                      } else {
                          Toast.makeText(getApplicationContext(), "Medicines not added into cart.", Toast.LENGTH_SHORT).show();
                      }
                      Intent intent = new Intent(Home.this, Cart.class);
                      startActivity(intent);
  
                  }
              });
  
              addMoreBtn.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
  
  
                      if (!med_nameET.getText().toString().matches("") &amp;&amp; !med_potencyET.getText().toString().matches("")
                              &amp;&amp; !med_qtyET.getText().toString().matches("0")) {
  
                          medOrderList.add(new MedicineBean(cust_id,med_nameET.getText().toString(),med_potencyET.getText().toString(),med_qtyET.getText().toString()));
                          med_nameET.setText("");
                          med_potencyET.setText("");
                          med_qtyET.setText("0");
                          adapter.notifyDataSetChanged();
  
                          Log.d("data",String.valueOf(medOrderList.size()));
  
                      }
                      else
                      {
                          Toast.makeText(getApplicationContext(), "Please fill all empty fields then press \'Add More\' button", Toast.LENGTH_SHORT).show();
                      }
  
                  }
              });
  
          }
          else
          {
              Intent intent = new Intent(Home.this, SignIn.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
              startActivity(intent);
          }
  
  
  
      }
  
  
  
  
  
  
  
  
  
  
  
  
      private class ListViewHolder{
  
          EditText medET;
          EditText potencyET;
          EditText incrOrDecET;
          ImageButton cancelBtn;
  
  
      }
  
      class CustomAdapter extends ArrayAdapter&lt;MedicineBean&gt; {
          private Context context;
          private List&lt;MedicineBean&gt; medicineBeanList;
          ListViewHolder listViewHolder;
  
          public CustomAdapter(Context context, int resource, ArrayList&lt;MedicineBean&gt; objects) {
  
              super(context, resource, objects);
              this.context = context;
              this.medicineBeanList = objects;
          }
  
          @Override
          public int getCount() {
              return medicineBeanList.size();
          }
  
          @Override
          public MedicineBean getItem(int i) {
              return medicineBeanList.get(i);
          }
  
          @Override
          public long getItemId(int i) {
              return i;
          }
  
          @Override
          public View getView(final int i, View view, ViewGroup viewGroup) {
  
  
              if(view==null) {
                  view = getLayoutInflater().inflate(R.layout.single_item, null);
                  listViewHolder = new ListViewHolder();
                  listViewHolder.medET = (EditText) view.findViewById(R.id.mediceNameInHomeList);
                  listViewHolder.potencyET = (EditText) view.findViewById(R.id.medicePotencyInHomeList);
                  listViewHolder.incrOrDecET = (EditText) view.findViewById(R.id.mediceQtyInHomeList);
                  listViewHolder.cancelBtn = (ImageButton) findViewById(R.id.homeCnclBtn);
                  listViewHolder.medET.setEnabled(false);
                  listViewHolder.potencyET.setEnabled(false);
                  listViewHolder.incrOrDecET.setEnabled(false);
                  view.setTag(listViewHolder);
  
  
                  listViewHolder.medET.setText(medicineBeanList.get(i).getMediceneName());
                  listViewHolder.potencyET.setText(medicineBeanList.get(i).getMedicenePotency());
                  listViewHolder.incrOrDecET.setText(medicineBeanList.get(i).getMediceneQty());
  
                  listViewHolder.cancelBtn.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          try {
  
  
                              adapter.remove(medicineBeanList.get(i));
                              adapter.notifyDataSetChanged();
                              /*for (int pos = 0; pos &lt; medOrderList.size(); pos++)
                              {
  
                                  listViewHolder.medET.setText(medOrderList.get(pos).getMediceneName());
                                  listViewHolder.potencyET.setText(medOrderList.get(pos).getMedicenePotency());
                                  listViewHolder.incrOrDecET.setText(medOrderList.get(pos).getMediceneQty());
                                  //adapter.add(new MedicineBean(medOrderList.get(pos).getCust_id(),medOrderList.get(pos).getMediceneName(),medOrderList.get(pos).getMedicenePotency(),medOrderList.get(pos).getMediceneQty()));
                              }*/
  
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
  
  
                      }
                  });
              }
  
              return view;
          }
  
      }
  
  
  
  }
  </code></pre>