Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Listview items sets to default after scrolling

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 422
    Answer it

    I have list view which uses base adapter class for each item view, when I make changes in one item of list view and scroll the list view the changed item sets to default value, I need to retain my values even after scrolling.

    @Override
    
    public View getView(final int position, View convertView, ViewGroup parent) {
    
    final ViewHolder holder;
    
    if (convertView == null) {
    
    convertView = l_Inflater.inflate(R.layout.dish, null);
    
    holder = new ViewHolder();
    
    //holder.check_out=(Button) convertView.findViewById(R.id.checkout);
    
    holder.txt_itemName = (TextView) convertView.findViewById(R.id.name);
    
    holder.txt_itemPrice = (TextView) convertView.findViewById(R.id.price);
    
    holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
    
    holder.quickAdd = (ImageView) convertView.findViewById(R.id.quickAdd);
    
    holder.quickRemove=(ImageView) convertView.findViewById(R.id.quickRemove);
    
    holder.txt_item=(TextView) convertView.findViewById(R.id.item);
    
    holder.quantity=(TextView) convertView.findViewById(R.id.quantity1);
    
    holder.dishLogo=(TextView) convertView.findViewById(R.id.dishLogo);
    
    convertView.setTag(holder);
    
    } else {
    
    holder = (ViewHolder) convertView.getTag();
    
    }
    
    // holder.txt_item.setTag(position); 
    
    final Integer dish_id = itemDetailsArrayList.get(position).getDishID();
    
    final DishDetails obj = itemDetailsArrayList.get(position);
    
    String quant=""+itemDetailsArrayList.get(position).getQuantity1();
    
    holder.quantity.setText("   "+quant+" remaining");
    
    holder.txt_itemName.setText(itemDetailsArrayList.get(position).getDishName());
    
    holder.txt_itemPrice.setText(" \u20B9"+" "+itemDetailsArrayList.get(position).getDishPrice());
    
    holder.itemImage.setScaleType(ScaleType.FIT_XY);
    
    str=itemDetailsArrayList.get(position).getDishName();
    
    char str1=str.charAt(0);
    
    holder.dishLogo.setText(""+str1);
    
    notifyDataSetChanged();
    
    holder.quickAdd.setOnClickListener(new OnClickListener() {
    
    public void onClick(View v) {
    
     ViewGroup parent = (ViewGroup) v.getParent();
    
                TextView tv = (TextView) parent.findViewById(R.id.item);
    
                int count = Integer.parseInt((String) holder.txt_item.getText());
    
                count++;
    
               
    
                holder.txt_item.setText(String.valueOf(count));
    
                i++;
    
                cartCount();
    
                notifyDataSetChanged();
    
    }
    
    
    });
    
    holder.quickRemove.setOnClickListener(new OnClickListener() {
    
    public void onClick(View v) {
    
     ViewGroup parent = (ViewGroup) v.getParent();
    
                TextView tv = (TextView) parent.findViewById(R.id.item);
    
                int count = Integer.parseInt((String) holder.txt_item.getText());
    
    
                if (count > 0) {
    
                    count--;
    
                    holder.txt_item.setText(String.valueOf(count));
    
                   
    
                    i--;
    
                    cartCount();
    
                   
    
                } 
    
                notifyDataSetChanged();
    
    }
    
    });
    
    if(holder.txt_item.getText().toString()==""){
    
    holder.txt_item.setText("0");
    
    }
    
    Float quantity = Float.parseFloat(holder.txt_item.getText().toString());
    
    obj.setQuantity(quantity);
    
    if(quantity==0.0){
    
    // notifyDataSetChanged();
    
    OrderStore.deleteOrderItem(dish_id);
    
    }
    
    else{
    
    //String amount=itemDetailsArrayList.get(position).getDishPrice();
    
    //int price=(int) (Integer.parseInt(amount)*quantity);
    
    //amountCount(price);
    
    //notifyDataSetChanged();
    
    OrderStore.saveOrderItem(dish_id, obj);
    
    }
    
    notifyDataSetChanged();
    
    return convertView;
    
    }

     

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: