-1

I am using the linked hashmap to populate values in expandable list .I successfully populate them. Here key is the menuitems and values are corresponding modifiers I places two buttons foe increasing and decreasing quantity of menu items .As it is the key I remove them and update them and again I put them in the list. This time they are inserting on the lastrow . How to placethem in same position as they were before deletion? The function where i update my key.

public void putminusquantity(int pos)
    {
        try
        {
            SaleDetailsMenuItems aa = (SaleDetailsMenuItems)listDataChild.keySet().toArray()[pos];  
            List<ModifList> modlist =listDataChild.get(aa);
            //modlist.add(mli);
            listDataChild.remove(aa);
            int qty = Integer.parseInt(aa.getQuantity());
            float priced = Float.parseFloat(aa.getPrice());
            //Double finaltotal1 = Math.round( priced * 100.0 ) / 100.0;
            //Toast.makeText(getApplicationContext(), finaltotal1.toString(), Toast.LENGTH_SHORT).show();
            System.out.println(qty);
            float priced1 = priced / qty;
            if(qty>1)
            {
                qty--;
                priced = priced1 * qty;
                String quantity1 = Integer.toString(qty);
                String price1 = Float.toString(priced);
                aa.setQuantity(quantity1);
                aa.setPrice(price1);
                listDataChild.put(aa, modlist);

                listviewAdapter = new ExpandableListAdapter(getApplicationContext(), listDataChild);
                list.setAdapter(listviewAdapter);
                listviewAdapter.notifyDataSetChanged();
                resetquantity();
                settotal();
            }
            else
            {
                Toast.makeText(getApplicationContext(), "Invalid Quantity", Toast.LENGTH_SHORT).show();
            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }

Here is the model class:

class SaleDetailsMenuItems extends Sale 
 {
  int i;
    private int id;
    private String name;
    private String price;
    private String quantity;
    private int statuss;
    private String itemnote;
    private long saledetailId;
    private long saleid;
    private int menutype;
    private long menu_id;
    private int istaxinclusive;
    private int coursing_id;
    private String seatname;
    private int seatId;
    private String reason;
    // private int discountdtls;
    private int istaxexmpt;
    private float taxpercent;
    //private float inctaxpercent;
    private float taxamt;
    private float incltaxamt;
    private int ordertype;
    private boolean istaxincl;
    private int storeid;
    private int crtdby;
    private int modby;
    private int status;

    public SaleDetailsMenuItems(int i1,String item, String quantity,
            String price, int id, int statuss,String itemnote) 
    {
        // TODO Auto-generated constructor stub
this.i=i1;
        this.id=id;
        this.name = item;
        this.quantity = quantity;
        this.price = price;
        this.statuss = statuss;
        this.itemnote = itemnote;
        //this.flag = flag;
    }


    public int getStatuss() {
        return statuss;
    }
    public void setStatuss(int statuss) {
        this.statuss = statuss;
    }
    public long getSaledetailId() {
        return saledetailId;
    }
    public void setSaledetailId(long saledetailId) {
        this.saledetailId = saledetailId;
    }
    public long getSaleid() {
        return saleid;
    }
    public void setSaleid(long saleid) {
        this.saleid = saleid;
    }
    public int getMenutype() {
        return menutype;
    }
    public void setMenutype(int menutype) {
        this.menutype = menutype;
    }
    public long getMenu_id() {
        return menu_id;
    }
    public void setMenu_id(long menu_id) {
        this.menu_id = menu_id;
    }
    public int getIstaxinclusive() {
        return istaxinclusive;
    }
    public void setIstaxinclusive(int istaxinclusive) {
        this.istaxinclusive = istaxinclusive;
    }
    public int getCoursing_id() {
        return coursing_id;
    }
    public void setCoursing_id(int coursing_id) {
        this.coursing_id = coursing_id;
    }
    public String getSeatname() {
        return seatname;
    }
    public void setSeatname(String seatname) {
        this.seatname = seatname;
    }
    public int getSeatId() {
        return seatId;
    }
    public void setSeatId(int seatId) {
        this.seatId = seatId;
    }
    public String getReason() {
        return reason;
    }
    public void setReason(String reason) {
        this.reason = reason;
    }
    public int getIstaxexmpt() {
        return istaxexmpt;
    }
    public void setIstaxexmpt(int istaxexmpt) {
        this.istaxexmpt = istaxexmpt;
    }
    public float getTaxpercent() {
        return taxpercent;
    }
    public void setTaxpercent(float taxpercent) {
        this.taxpercent = taxpercent;
    }
    public float getTaxamt() {
        return taxamt;
    }
    public void setTaxamt(float taxamt) {
        this.taxamt = taxamt;
    }
    public float getIncltaxamt() {
        return incltaxamt;
    }
    public void setIncltaxamt(float incltaxamt) {
        this.incltaxamt = incltaxamt;
    }
    public int getOrdertype() {
        return ordertype;
    }
    public void setOrdertype(int ordertype) {
        this.ordertype = ordertype;
    }
    public boolean isIstaxincl() {
        return istaxincl;
    }
    public void setIstaxincl(boolean istaxincl) {
        this.istaxincl = istaxincl;
    }
    public int getStoreid() {
        return storeid;
    }
    public void setStoreid(int storeid) {
        this.storeid = storeid;
    }
    public int getCrtdby() {
        return crtdby;
    }
    public void setCrtdby(int crtdby) {
        this.crtdby = crtdby;
    }
    public int getModby() {
        return modby;
    }
    public void setModby(int modby) {
        this.modby = modby;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPrice() {
        return price;
    }
    public void setPrice(String price) {
        this.price = price;
    }
    public String getQuantity() {
        return quantity;
    }
    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public int getStatus() {
        return statuss;
    }
    public void setStatus(int statuss) {
        this.statuss = statuss;
    }
    public String getItemnote() {
        return itemnote;
    }
    public void setItemnote(String itemnote) {
        this.itemnote = itemnote;
    }

} I am using this class's object as key in my Map.

1 Answers1

0
TreeMap 

Is the way to sort the map by key. May be this will help you