[Solved] My list view is lagging can anyone help me to fix this?


if you still happy with ListView then you can take idea from below
code

here i am using Cursor but you can use ArrayList in place of Cursor

public class Custom_Adapter_Products extends BaseAdapter {
    Context context;
    Cursor mCursor; 
    static int[] intArr;
    DatabaseAdapter db;
    public ImageLoader imageLoader;

    public Custom_Adapter_Products(Context context, Cursor mCursor){
        this.context = context;
        this.mCursor = mCursor;
        this.intArr = new int[this.mCursor.getCount()];
        imageLoader=new ImageLoader(context);
    }

    @Override
    public int getCount() {     
        return mCursor.getCount();
    }

    @Override
    public Object getItem(int position) {

        return null;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {       
        try{            
                ViewHolder holder;
                this.mCursor.moveToPosition(position);
                LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                if (convertView == null)
                {
                    convertView = vi.inflate(R.layout.lv_row_for_products, null);
                    holder = createViewHolder(convertView);
                    convertView.setTag(holder);
                    holder.btnMinus.setTag(holder);
                    holder.btnAdd.setTag(holder);
                } 
                else
                {
                    holder = (ViewHolder) convertView.getTag();                
                }           

                holder.btnMinus.setOnClickListener(new OnClickListener() {              
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    try{
                        ViewHolder holder = (ViewHolder) v.getTag();
                        // Do whatever you want
                    }catch (Exception e) {
                        // TODO: handle exception
                        e.printStackTrace();
                    }
                }
            });



        }catch (Exception e){
            // TODO: handle exception
            e.printStackTrace();
        }
        return convertView;
    }   


    private static class ViewHolder
    {
        public TextView tvProductName;
        public TextView tvPrice;
        public TextView tvMRP;
        public TextView tvMOQ;
        public TextView tvPercent;
        public TextView tvQuantity;       
        public ImageView imgProduct;
        public ProgressBar pBar;
        public Button btnMinus;
        public Button btnAdd;       
    }

    private ViewHolder createViewHolder(View v) {
        ViewHolder holder = new ViewHolder();
        try{
            holder.tvProductName = (TextView) v.findViewById(R.id.tvProductName);
            holder.tvPrice = (TextView) v.findViewById(R.id.tvPrice);
            holder.tvMRP = (TextView) v.findViewById(R.id.tvMRP);
            holder.tvMOQ = (TextView) v.findViewById(R.id.tvMOQ);
            holder.tvQuantity = (TextView) v.findViewById(R.id.tvQuantity);
            holder.imgProduct = (ImageView) v.findViewById(R.id.imgProduct);
            holder.pBar = (ProgressBar) v.findViewById(R.id.img_pb);
            holder.btnMinus = (Button) v.findViewById(R.id.btnMinus);
            holder.btnAdd = (Button) v.findViewById(R.id.btnAdd);
            holder.tvPercent = (TextView) v.findViewById(R.id.tvPercent);
        }catch (Exception e) {
        // TODO: handle exception
            e.printStackTrace();
    }
        return holder;
    }
}

0

solved My list view is lagging can anyone help me to fix this?