Android 获取listview中的数据

Android 获取listview中的数据,android,listview,Android,Listview,当我点击查看按钮时,它会在listview Sr、Item、Quantity和Prize中显示4个字段。 我可以在Listview中获取数据,但问题是当我增加3倍时,它会显示所有的增加值。假设一个项目的价格是5。它会显示 1-5,2-10,3-15。但是如果3-15增加了3倍,我直接想显示它。我也添加了xml。提前感谢您的帮助。 下面是我的代码- MainActivity.java import android.app.Activity; import android.cont

当我点击查看按钮时,它会在listview Sr、Item、Quantity和Prize中显示4个字段。 我可以在Listview中获取数据,但问题是当我增加3倍时,它会显示所有的增加值。假设一个项目的价格是5。它会显示 1-5,2-10,3-15。但是如果3-15增加了3倍,我直接想显示它。我也添加了xml。提前感谢您的帮助。 下面是我的代码-

MainActivity.java

    import android.app.Activity;
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.support.v7.widget.SearchView;
    import android.text.TextUtils;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.Toast;
    import java.util.ArrayList;

    public class MainActivity extends Activity {

    Button show;
        ListView list_item;
        private ArrayList<Integer> sr;
        private ArrayList<String> item;
        private ArrayList<Integer> quantity;
        private ArrayList<Integer> price;


        private ArrayList<Integer> sr1;
        private ArrayList<String> item1;
        private ArrayList<Integer> price1;
        private ArrayList<Integer> data1;
        SearchView searchView;
        private ArrayList<String> filterlist;
        public Custom custom;



        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);


            list_item = (ListView) findViewById(R.id.listdetails);



            show=(Button)findViewById(R.id.btnview);
            sr = new ArrayList<>();
            item = new ArrayList<>();
            quantity = new ArrayList<>();
            price = new ArrayList<>();

            sr1 = new ArrayList<>();
            item1 = new ArrayList<>();
            data1= new ArrayList<>();
            price1= new ArrayList<>();

            filterlist = new ArrayList<>();
            item = filterlist;


            sr.add(1);
            sr.add(2);
            sr.add(3);
            sr.add(4);

            item.add("Book");
            item.add("pen");
            item.add("pencil");
            item.add("Eraser");


            quantity.add(0);
            quantity.add(0);
            quantity.add(0);
            quantity.add(0);


            price.add(20);
            price.add(30);
            price.add(5);
            price.add(5);


            Custom c = new Custom(this, sr, item, quantity, price,sr1,item1,data1,price1);
            list_item.setAdapter(c);

            show.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(MainActivity.this,Trial.class);
                    intent.putExtra("sr",sr1);
                    intent.putExtra("item",item1);
                    intent.putExtra("qty",data1);
                    intent.putExtra("price",price1);
                    startActivity(intent);
                }
            });

        }

    }


    Custom.java

    import android.app.Activity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.Button;
    import android.widget.Filter;
    import android.widget.Filterable;
    import android.widget.TextView;

    import java.util.ArrayList;

    public class Custom  extends BaseAdapter {

        Activity a;
        public ArrayList<Integer> sr;
        public ArrayList<String> item;
        public ArrayList<Integer> quantity;
        public ArrayList<Integer> price;


        public ArrayList<Integer> sr1;
        public ArrayList<String> item1;
        public ArrayList<Integer> data1;
        public ArrayList<Integer> price1;
        public ArrayList<String> filterlist;


        int bookCount = 0;
        int penCount = 0;
        int pencilCount = 0;
        int eraserCount=0;

        int bookPrice = 0;
        int penPrice = 0;
        int pencilPrice = 0;
        int eraserPrice=0;


        private String data, pricedata;

        public Custom(Activity a, ArrayList<Integer> sr, ArrayList<String> item, ArrayList<Integer> quantity, ArrayList<Integer> price, ArrayList<Integer> sr1, ArrayList<String> item1, ArrayList<Integer> data1, ArrayList<Integer> price1) {
            this.a = a;
            this.sr = sr;
            this.item = item;
            this.quantity = quantity;
            this.price = price;
            this.sr1 = sr1;
            this.item1 = item1;
            this.data1 = data1;
            this.price1 = price1;
        }



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

        @Override
        public Object getItem(int position) {
            return item.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }


        public class Holder{
            TextView sr1,item1,qty1,price1;
            Button pl,min;

        }


        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            final Holder holder=new Holder();
            LayoutInflater li=a.getLayoutInflater();
            final View view=li.inflate(R.layout.customlist,parent,false);

            holder.sr1=(TextView)view.findViewById(R.id.s_no);
            holder.item1=(TextView)view.findViewById(R.id.i_name);
            holder.qty1=(TextView)view.findViewById(R.id.qty);
            holder.price1=(TextView)view.findViewById(R.id.pr);
            holder.pl=(Button) view.findViewById(R.id.pl);
            holder.min=(Button)view.findViewById(R.id.min);


            holder.sr1.setText(String.valueOf(sr.get(position)));
            holder.item1.setText(item.get(position));
            holder.qty1.setText(String.valueOf(quantity.get(position)));
            holder.price1.setText(String.valueOf(price.get(position)));


            holder.pl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    switch (position) {
                        case 0:
                            if (bookCount >= 0) {
                                bookCount++;
                                bookPrice = bookPrice + 20;
                                sr.get(position);
                                item.get(position);

                            }
                            break;

                        case 1:
                            if (penCount >= 0) {
                                penCount++;
                                penPrice += 30;

                                sr.get(position);
                                item.get(position);

                            }
                            break;
                        case 2:
                            if (pencilCount >= 0) {
                                pencilCount++;
                                pencilPrice += 5;

                                sr.get(position);
                                item.get(position);

                            }
                            break;
                        case 3:
                            if(eraserCount>=0){
                                eraserCount++;
                                eraserPrice +=5;

                                sr.get(position);
                                item.get(position);


                            }
                            break;
                    }
                  if(position==0)
                  {
                      holder.qty1.setText(String.valueOf(bookCount));
                      holder.price1.setText(String.valueOf(bookPrice));

                      sr1.add(sr.get(position));
                      item1.add(item.get(position));
                      data1.add(bookCount);
                      price1.add(bookPrice);
                  }
                    else if(position==1)
                  {
                      holder.qty1.setText(String.valueOf(penCount));
                      holder.price1.setText(String.valueOf(penPrice));

                      sr1.add(sr.get(position));
                      item1.add(item.get(position));
                      data1.add(penCount);
                      price1.add(penPrice);
                  }
                    else if(position==2)
                  {
                      holder.qty1.setText(String.valueOf(pencilCount));
                      holder.price1.setText(String.valueOf(pencilPrice));

                      sr1.add(sr.get(position));
                      item1.add(item.get(position));
                      data1.add(pencilCount);
                      price1.add(pencilPrice);
                  }
                    else if(position==3)
                  {
                      holder.qty1.setText(String.valueOf(eraserCount));
                      holder.price1.setText(String.valueOf(eraserPrice));

                      sr1.add(sr.get(position));
                      item1.add(item.get(position));
                      data1.add(eraserCount);
                      price1.add(eraserPrice);

                  }


                }
            });





            holder.min.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    switch (position) {
                        case 0:
                            if (bookCount > 0) {
                                bookCount--;
                                bookPrice -= 20;

                                sr.get(position);
                                item.get(position);

                            }
                            break;
                        case 1:
                            if (penCount > 0) {
                                penCount--;
                                penPrice -= 30;

                                sr.get(position);
                                item.get(position);

                            }
                            break;

                        case 2:
                            if (pencilCount > 0) {
                                pencilCount--;
                                pencilPrice -= 5;

                                sr.get(position);
                                item.get(position);

                            }
                            break;
                        case 3:
                            if(eraserCount > 0){
                                eraserCount--;
                                eraserPrice-=5;

                                sr.get(position);
                                item.get(position);

                            }
                            break;
                    }

                    if(position==0)
                    {
                        holder.qty1.setText(String.valueOf(bookCount));
                        holder.price1.setText(String.valueOf(bookPrice));

                        sr1.add(sr.get(position));
                        item1.add(item.get(position));
                        data1.add(bookCount);
                        price1.add(bookPrice);
                    }
                    else if(position==1)
                    {
                        holder.qty1.setText(String.valueOf(penCount));
                        holder.price1.setText(String.valueOf(penPrice));

                        sr1.add(sr.get(position));
                        item1.add(item.get(position));
                        data1.add(penCount);
                        price1.add(penPrice);
                    }
                    else if(position==2)
                    {
                        holder.qty1.setText(String.valueOf(pencilCount));
                        holder.price1.setText(String.valueOf(pencilPrice));

                        sr1.add(sr.get(position));
                        item1.add(item.get(position));
                        data1.add(pencilCount);
                        price1.add(pencilPrice);
                    }
                    else if(position==3)
                    {
                        holder.qty1.setText(String.valueOf(eraserCount));
                        holder.price1.setText(String.valueOf(eraserPrice));

                        sr1.add(sr.get(position));
                        item1.add(item.get(position));
                        data1.add(eraserCount);
                        price1.add(eraserPrice);

                    }


                }
            });

            return view;


        }


    }


    Trial.java
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ListView;
    import android.widget.TextView;

    import java.util.ArrayList;


    public class Trial extends Activity {
        ListView listnew;


        ArrayList<Integer> sr1;
        ArrayList<String> item1;
        ArrayList<Integer> data;
        ArrayList<Integer> price;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.trial);
            data=new ArrayList<>();
            price=new ArrayList<>();
            listnew=(ListView)findViewById(R.id.newlist);

            Bundle bundle=getIntent().getExtras();
            sr1=bundle.getIntegerArrayList("sr");
            item1=bundle.getStringArrayList("item");
            data=bundle.getIntegerArrayList("qty");
            price=bundle.getIntegerArrayList("price");


            Custom_Trial ct=new Custom_Trial(this,sr1,item1,data,price);
            listnew.setAdapter(ct);

        }
    }


    CustomTrial.java
    package com.example.ram.logic;
    import android.app.Activity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.TextView;

    import java.util.ArrayList;

    public class Custom_Trial extends BaseAdapter {
        Activity a;

        ArrayList<Integer> sr1;
        ArrayList<String> item1;
        ArrayList<Integer> data;
        ArrayList<Integer> price;

        public Custom_Trial(Activity a, ArrayList<Integer> sr1, ArrayList<String> item1, ArrayList<Integer> data, ArrayList<Integer> price) {
            this.a = a;
            this.sr1 = sr1;
            this.item1 = item1;
            this.data = data;
            this.price = price;
        }

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

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }
        public class Holder{
            TextView sr,it,qty,amt;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder holder=new Holder();
            LayoutInflater li=a.getLayoutInflater();
            View view=li.inflate(R.layout.customtrial,parent,false);
            holder.sr=(TextView)view.findViewById(R.id.head1);
            holder.it=(TextView)view.findViewById(R.id.head2);
            holder.qty=(TextView)view.findViewById(R.id.head3);
            holder.amt=(TextView)view.findViewById(R.id.head4);

            holder.sr.setText(String.valueOf(sr1.get(position)));
            holder.it.setText(item1.get(position));
            holder.qty.setText(String.valueOf(data.get(position)));
            holder.amt.setText(String.valueOf(price.get(position)));



            return view;
        }
    }


activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.abc.logic.MainActivity">


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/item_name"
        android:orientation="horizontal"
        android:layout_toRightOf="@+id/sr_no"

        >
        <TextView
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/srno"
            android:layout_below="@+id/breakfast"
            android:text="ITEM NAME"
            android:id="@+id/itemname"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#000"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/qtity"
        android:orientation="horizontal"
        android:layout_toRightOf="@+id/item_name"

        >
        <TextView
            android:layout_width="40dp"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/itemname"
            android:layout_below="@+id/lunch"
            android:text="QTY"
            android:id="@+id/quantity"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#000"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/count"
        android:layout_toRightOf="@+id/qtity"

        >
        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rate"
        android:orientation="horizontal"
        android:layout_toRightOf="@+id/count"

        >
        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/quantity"
            android:layout_below="@+id/snacks"
            android:text="PRICE"
            android:id="@+id/price"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#000"
            />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/sr_no"
        android:orientation="horizontal"

        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">
        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_below="@+id/breakfast"
            android:layout_margin="2dp"
            android:layout_marginTop="10dp"
            android:text="SR.NO"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#000"
            android:id="@+id/srno"
            />

    </LinearLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:id="@+id/listdetails"
        android:scrollbars="vertical"
        android:layout_below="@+id/item_name"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">


    </ListView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnview"
        android:text="View"
        android:layout_below="@+id/listdetails"
        android:clickable="true">

    </Button>


</RelativeLayout>


customlist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/s_no"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:textColor="#000"
        android:textStyle="bold"
        />
    <TextView
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:gravity="center"
        android:textColor="#000"
        android:textStyle="bold"
        android:id="@+id/i_name"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/s_no"
        />

    <Button
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:id="@+id/pl"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/qty"
        android:background="@drawable/plus1"
        />
    <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/qty"
        android:layout_toRightOf="@id/i_name"
        android:gravity="center"
        android:textColor="#000"
        android:textStyle="bold"
        android:layout_marginTop="5dp"
        />

    <Button
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:id="@+id/min"
        android:layout_marginTop="3dp"
        android:layout_below="@id/pl"
        android:layout_toRightOf="@id/qty"
        android:background="@drawable/minus1"
        />

    <TextView
        android:layout_width="60dp"
        android:layout_height="50dp"
        android:id="@+id/pr"
        android:gravity="center"
        android:textColor="#000"
        android:textStyle="bold"
        android:layout_marginLeft="10dp"
        android:layout_alignBottom="@+id/min"
        android:layout_toRightOf="@+id/pl"
        android:layout_toEndOf="@+id/pl" />




</RelativeLayout>


customtrial.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head1"
        android:paddingLeft="10dp"
        android:gravity="center"
        android:textSize="20dp"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head2"
        android:layout_toRightOf="@+id/head1"
        android:textSize="20dp"
        android:gravity="center"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head3"
        android:layout_toRightOf="@+id/head2"
        android:textSize="20dp"
        android:gravity="center"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head4"
        android:layout_toRightOf="@+id/head3"
        android:textSize="20dp"
        android:gravity="center"
        />
</RelativeLayout>



trial.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">



    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head1"
        android:text="SrNo"
        android:paddingLeft="10dp"
        android:gravity="center"
        android:textSize="20dp"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head2"
        android:layout_toRightOf="@+id/head1"
        android:textSize="20dp"
        android:gravity="center"
        android:text="Item"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head3"
        android:text="Qty"
        android:layout_toRightOf="@+id/head2"
        android:paddingLeft="10dp"
        android:gravity="center"
        android:textSize="20dp"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:id="@+id/head4"
        android:layout_toRightOf="@+id/head3"
        android:textSize="20dp"
        android:gravity="center"
        android:text="Price"
        />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:id="@+id/newlist"
        android:scrollbars="vertical"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/head1"

        >


    </ListView>




</RelativeLayout>
MainActivity.java
导入android.app.Activity;
导入android.content.Intent;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.support.v7.widget.SearchView;
导入android.text.TextUtils;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.Toast;
导入java.util.ArrayList;
公共类MainActivity扩展了活动{
按钮显示;
列表视图列表项;
私人ArrayList sr;
私有数组列表项;
私有数组列表数量;
私人拍卖价格;
私人ArrayList sr1;
私有数组列表项1;
私人ArrayList价格1;
私有ArrayList数据1;
搜索视图搜索视图;
私有数组列表过滤器列表;
公共习俗;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
列表项=(ListView)findViewById(R.id.listdetails);
show=(按钮)findViewById(R.id.btnview);
sr=新的ArrayList();
item=newarraylist();
数量=新的ArrayList();
价格=新的ArrayList();
sr1=新的ArrayList();
item1=新的ArrayList();
data1=新的ArrayList();
price1=新的ArrayList();
filterlist=newarraylist();
项目=过滤器列表;
sr.add(1);
sr.add(2);
sr.add(3);
sr.add(4);
项目。添加(“账簿”);
项目。添加(“笔”);
项目。添加(“铅笔”);
添加(“橡皮擦”);
数量。添加(0);
数量。添加(0);
数量。添加(0);
数量。添加(0);
价格。添加(20);
价格。添加(30);
价格。添加(5);
价格。添加(5);
自定义c=新自定义(此、sr、项目、数量、价格、sr1、项目1、数据1、价格1);
列表项。设置适配器(c);
show.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
意图=新的意图(MainActivity.this,Trial.class);
意向。额外(“sr”,sr1);
意向。额外(“项目”,第1项);
意向额外(“数量”,数据1);
意向。额外支付(“价格”,价格1);
星触觉(意向);
}
});
}
}
Custom.java
导入android.app.Activity;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.BaseAdapter;
导入android.widget.Button;
导入android.widget.Filter;
导入android.widget.Filterable;
导入android.widget.TextView;
导入java.util.ArrayList;
公共类自定义扩展BaseAdapter{
活动a;
公共检察官;
公共阵列列表项;
公共阵列列表数量;
公开拍卖价格;
公共阵列列表sr1;
公共阵列列表项目1;
公共阵列列表数据1;
公共阵列列表价格1;
公共阵列列表过滤器列表;
int bookCount=0;
int penCount=0;
整数铅笔计数=0;
int橡皮擦计数=0;
int bookPrice=0;
int-penPrice=0;
国际铅笔价格=0;
int-eraserPrice=0;
私有字符串数据,pricedata;
公共自定义(活动a、ArrayList sr、ArrayList项目、ArrayList数量、ArrayList价格、ArrayList sr1、ArrayList项目1、ArrayList数据1、ArrayList价格1){
这个a=a;
this.sr=sr;
this.item=项目;
这个。数量=数量;
这个价格=价格;
这1.sr1=sr1;
这个项目1=项目1;
this.data1=data1;
这个价格1=价格1;
}
@凌驾
public int getCount(){
返回item.size();
}
@凌驾
公共对象getItem(int位置){
返回项目。获取(位置);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
公共类持有者{
TextView sr1,第1项,第1季度,价格1;
按钮pl,最小值;
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
最终支架=新支架();
LayoutInflater li=a.getLayoutInflater();
最终视图=li.inflate(R.layout.customlist,parent,false);
holder.sr1=(TextView)view.findViewById(R.id.s_编号);
holder.item1=(TextView)view.findViewById(R.id.i_name);
holder.qty1=(TextView)view.findViewById(R.id.qty);
holder.price1=(TextView)view.findViewById(R.id.pr);
holder.pl=(Button)view.findViewById(R.id.pl);
holder.min=(按钮)view.findViewById(R.id.min);
holder.sr1.setText(String.valueOf(sr.get(position));
holder.item1.setText(item.get(position));
holder.qty1.setText(String.valueOf(quantity.get(position));
holder.price1.setText(String.valueOf(price.get(position));
holder.pl.setOnClickListener(新
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MainActivityList extends Activity {

Button show;
ListView list_item;
ArrayList<Model> models = new ArrayList<>();
public Custom custom;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);


    list_item = (ListView) findViewById(R.id.listdetails);


    show = (Button) findViewById(R.id.btnview);

    Model model = new Model();
    model.setItemName("Book");
    model.setPrice("10");
    model.setQty("0");
    model.setSrNo("1");
    model.setTotalSum("0");
    models.add(model);

    model = new Model();
    model.setItemName("Eraser");
    model.setPrice("5");
    model.setQty("0");
    model.setSrNo("1");
    model.setTotalSum("0");
    models.add(model);

    model = new Model();
    model.setItemName("Pen");
    model.setPrice("5");
    model.setQty("0");
    model.setSrNo("1");
    model.setTotalSum("0");
    models.add(model);

    model = new Model();
    model.setItemName("Pencil");
    model.setPrice("5");
    model.setQty("0");
    model.setSrNo("1");
    model.setTotalSum("0");
    models.add(model);


    Custom c = new Custom();
    list_item.setAdapter(c);

    show.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(MainActivityList.this,Trial.class);
            intent.putExtra("data",models);
            startActivity(intent);
        }
    });

}

public class Custom extends BaseAdapter {

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

    @Override
    public Object getItem(int position) {
        return models.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public class Holder {
        TextView sr1, item1, qty1, price1;
        Button pl, min;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final Holder holder = new Holder();
        LayoutInflater li = MainActivityList.this.getLayoutInflater();
        final View view = li.inflate(R.layout.customlist, parent, false);

        holder.sr1 = (TextView) view.findViewById(R.id.s_no);
        holder.item1 = (TextView) view.findViewById(R.id.i_name);
        holder.qty1 = (TextView) view.findViewById(R.id.qty);
        holder.price1 = (TextView) view.findViewById(R.id.pr);
        holder.pl = (Button) view.findViewById(R.id.pl);
        holder.min = (Button) view.findViewById(R.id.min);


        final Model model = models.get(position);

        holder.sr1.setText(String.valueOf(model.getSrNo()));
        holder.item1.setText(model.getItemName());
        holder.qty1.setText(String.valueOf(model.getQty()));
        holder.price1.setText(String.valueOf(model.getTotalSum()));


        holder.pl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int temp = Integer.parseInt(model.getQty()) + 1;
                int tempPrice = Integer.parseInt(model.getPrice()) * temp;

                model.setTotalSum(tempPrice + "");
                model.setQty(temp + "");
                notifyDataSetChanged();

            }
        });


        holder.min.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  int temp = Integer.parseInt(model.getQty()) - 1;
                  if (temp > 0) {
                      int tempPrice = Integer.parseInt(model.getPrice()) * temp;
                      model.setTotalSum(tempPrice + "");
                      model.setQty(temp + "");
                  } else {
                      int tempPrice = Integer.parseInt(model.getPrice()) * 0;
                      model.setTotalSum(tempPrice + "");
                      model.setQty(0 + "");
                  }
                  notifyDataSetChanged();
              }
          }

        );

        return view;

    }

}
}
            package com.demostudies;

        import android.app.Activity;
        import android.os.Bundle;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.BaseAdapter;
        import android.widget.ListView;
        import android.widget.TextView;

        import java.util.ArrayList;


        public class Trial extends Activity {
        ListView listnew;
        private ArrayList<Model> data = new ArrayList<>();

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.trial);

            listnew = (ListView) findViewById(R.id.newlist);


            data.addAll((ArrayList<Model>) getIntent().getSerializableExtra("data"));

            Custom_Trial ct = new Custom_Trial();
            listnew.setAdapter(ct);

        }

        class Custom_Trial extends BaseAdapter {

            @Override
            public int getCount() {

                return data.size();
            }

            @Override
            public Object getItem(int position) {
                return data.get(position);
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            public class Holder {
                TextView sr, it, qty, amt;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                Holder holder = new Holder();
                LayoutInflater li = Trial.this.getLayoutInflater();
                View view = li.inflate(R.layout.customtrial, parent, false);
                holder.sr = (TextView) view.findViewById(R.id.head1);
                holder.it = (TextView) view.findViewById(R.id.head2);
                holder.qty = (TextView) view.findViewById(R.id.head3);
                holder.amt = (TextView) view.findViewById(R.id.head4);

                Model m = data.get(position);
                holder.sr.setText(String.valueOf(m.getSrNo()));
                holder.it.setText(m.getItemName());
                holder.qty.setText(String.valueOf(m.getQty()));
                holder.amt.setText(String.valueOf(m.getTotalSum()));


                return view;
            }
        }
    }
    import java.io.Serializable;
    public class Model  implements Serializable

        {
            String qty, itemName, price, srNo, totalSum;

        public String getQty() {
            return qty;
        }

        public void setQty(String qty) {
            this.qty = qty;
        }

        public String getItemName() {
            return itemName;
        }

        public void setItemName(String itemName) {
            this.itemName = itemName;
        }

        public String getPrice() {
            return price;
        }

        public void setPrice(String price) {
            this.price = price;
        }

        public String getSrNo() {
            return srNo;
        }

        public void setSrNo(String srNo) {
            this.srNo = srNo;
        }

        public String getTotalSum() {
            return totalSum;
        }

        public void setTotalSum(String totalSum) {
            this.totalSum = totalSum;
        }
    }
        import android.app.Activity;
        import android.content.Intent;
        import android.os.Bundle;
        import android.support.v7.widget.SearchView;
        import android.view.View;
        import android.widget.Button;
        import android.widget.ListView;

        import java.util.ArrayList;
        import java.util.LinkedHashSet;
        import java.util.Set;


        import android.view.LayoutInflater;
        import android.view.ViewGroup;
        import android.widget.BaseAdapter;
        import android.widget.TextView;


        public class MainActivityList extends Activity {

            Button show;
            ListView list_item;
            private ArrayList<Integer> sr;
            private ArrayList<String> item;
            private ArrayList<Integer> quantity;
            private ArrayList<Integer> price;


            private ArrayList<Integer> sr1;
            private ArrayList<String> item1;
            private ArrayList<Integer> price1;
            private ArrayList<Integer> data1;
            SearchView searchView;
            private ArrayList<String> filterlist;
            public Custom custom;

            int bookCount = 0;
            int penCount = 0;
            int pencilCount = 0;
            int eraserCount=0;

            int bookPrice = 0;
            int penPrice = 0;
            int pencilPrice = 0;
            int eraserPrice=0;



            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main_list);


                list_item = (ListView) findViewById(R.id.listdetails);



                show=(Button)findViewById(R.id.btnview);
                sr = new ArrayList<>();
                item = new ArrayList<>();
                quantity = new ArrayList<>();
                price = new ArrayList<>();

                sr1 = new ArrayList<>();
                item1 = new ArrayList<>();
                data1= new ArrayList<>();
                price1= new ArrayList<>();

                filterlist = new ArrayList<>();
                item = filterlist;


                sr.add(1);
                sr.add(2);
                sr.add(3);
                sr.add(4);

                item.add("Book");
                item.add("pen");
                item.add("pencil");
                item.add("Eraser");


                quantity.add(0);
                quantity.add(0);
                quantity.add(0);
                quantity.add(0);


                price.add(20);
                price.add(30);
                price.add(5);
                price.add(5);


                Custom c = new Custom(this, sr, item, quantity, price,sr1,item1,data1,price1);
                list_item.setAdapter(c);

                show.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(MainActivityList.this,Trial.class);
                        Set<Integer> s = new LinkedHashSet<>();
                        s.addAll(sr);
                        sr.clear();
                        sr.addAll(s);

                        Set<String> ss = new LinkedHashSet<>();
                        ss.addAll(item);
                        item.clear();
                        item.addAll(ss);

                        data1.clear();
                        price1.clear();

                        for(Integer srn: sr){
                            if(srn==1){
                                data1.add(bookCount);
                                price1.add(bookPrice);
                            }

                            if(srn==2){
                                data1.add(penCount);
                                price1.add(penPrice);
                            }

                            if(srn==3){
                                data1.add(pencilCount);
                                price1.add(pencilPrice);
                            }

                            if(srn==4){
                                data1.add(eraserCount);
                                price1.add(eraserPrice);
                            }
                        }


                        intent.putExtra("sr",sr);
                        intent.putExtra("item",item);
                        intent.putExtra("qty",data1);
                        intent.putExtra("price",price1);
                        startActivity(intent);
                    }
                });

            }

            public class Custom  extends BaseAdapter {

                Activity a;
                public ArrayList<Integer> sr;
                public ArrayList<String> item;
                public ArrayList<Integer> quantity;
                public ArrayList<Integer> price;


                public ArrayList<Integer> sr1;
                public ArrayList<String> item1;
                public ArrayList<Integer> data1;
                public ArrayList<Integer> price1;
                public ArrayList<String> filterlist;




                private String data, pricedata;

                public Custom(Activity a, ArrayList<Integer> sr, ArrayList<String> item, ArrayList<Integer> quantity, ArrayList<Integer> price, ArrayList<Integer> sr1, ArrayList<String> item1, ArrayList<Integer> data1, ArrayList<Integer> price1) {
                    this.a = a;
                    this.sr = sr;
                    this.item = item;
                    this.quantity = quantity;
                    this.price = price;
                    this.sr1 = sr1;
                    this.item1 = item1;
                    this.data1 = data1;
                    this.price1 = price1;
                }



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

                @Override
                public Object getItem(int position) {
                    return item.get(position);
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }


                public class Holder{
                    TextView sr1,item1,qty1,price1;
                    Button pl,min;

                }


                @Override
                public View getView(final int position, View convertView, ViewGroup parent) {
                    final Holder holder=new Holder();
                    LayoutInflater li=a.getLayoutInflater();
                    final View view=li.inflate(R.layout.customlist,parent,false);

                    holder.sr1=(TextView)view.findViewById(R.id.s_no);
                    holder.item1=(TextView)view.findViewById(R.id.i_name);
                    holder.qty1=(TextView)view.findViewById(R.id.qty);
                    holder.price1=(TextView)view.findViewById(R.id.pr);
                    holder.pl=(Button) view.findViewById(R.id.pl);
                    holder.min=(Button)view.findViewById(R.id.min);


                    holder.sr1.setText(String.valueOf(sr.get(position)));
                    holder.item1.setText(item.get(position));
                    holder.qty1.setText(String.valueOf(quantity.get(position)));
                    holder.price1.setText(String.valueOf(price.get(position)));


                    holder.pl.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            switch (position) {
                                case 0:
                                    if (bookCount >= 0) {
                                        bookCount++;
                                        bookPrice = bookPrice + 20;
                                        sr.get(position);
                                        item.get(position);

                                    }
                                    break;

                                case 1:
                                    if (penCount >= 0) {
                                        penCount++;
                                        penPrice += 30;

                                        sr.get(position);
                                        item.get(position);

                                    }
                                    break;
                                case 2:
                                    if (pencilCount >= 0) {
                                        pencilCount++;
                                        pencilPrice += 5;

                                        sr.get(position);
                                        item.get(position);

                                    }
                                    break;
                                case 3:
                                    if(eraserCount>=0){
                                        eraserCount++;
                                        eraserPrice +=5;

                                        sr.get(position);
                                        item.get(position);


                                    }
                                    break;
                            }
                            if(position==0)
                            {
                                holder.qty1.setText(String.valueOf(bookCount));
                                holder.price1.setText(String.valueOf(bookPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(bookCount);
                                price1.add(bookPrice);
                            }
                            else if(position==1)
                            {
                                holder.qty1.setText(String.valueOf(penCount));
                                holder.price1.setText(String.valueOf(penPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(penCount);
                                price1.add(penPrice);
                            }
                            else if(position==2)
                            {
                                holder.qty1.setText(String.valueOf(pencilCount));
                                holder.price1.setText(String.valueOf(pencilPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(pencilCount);
                                price1.add(pencilPrice);
                            }
                            else if(position==3)
                            {
                                holder.qty1.setText(String.valueOf(eraserCount));
                                holder.price1.setText(String.valueOf(eraserPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(eraserCount);
                                price1.add(eraserPrice);

                            }


                        }
                    });





                    holder.min.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            switch (position) {
                                case 0:
                                    if (bookCount > 0) {
                                        bookCount--;
                                        bookPrice -= 20;

                                        sr.get(position);
                                        item.get(position);

                                    }
                                    break;
                                case 1:
                                    if (penCount > 0) {
                                        penCount--;
                                        penPrice -= 30;

                                        sr.get(position);
                                        item.get(position);

                                    }
                                    break;

                                case 2:
                                    if (pencilCount > 0) {
                                        pencilCount--;
                                        pencilPrice -= 5;

                                        sr.get(position);
                                        item.get(position);

                                    }
                                    break;
                                case 3:
                                    if(eraserCount > 0){
                                        eraserCount--;
                                        eraserPrice-=5;

                                        sr.get(position);
                                        item.get(position);

                                    }
                                    break;
                            }

                            if(position==0)
                            {
                                holder.qty1.setText(String.valueOf(bookCount));
                                holder.price1.setText(String.valueOf(bookPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(bookCount);
                                price1.add(bookPrice);
                            }
                            else if(position==1)
                            {
                                holder.qty1.setText(String.valueOf(penCount));
                                holder.price1.setText(String.valueOf(penPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(penCount);
                                price1.add(penPrice);
                            }
                            else if(position==2)
                            {
                                holder.qty1.setText(String.valueOf(pencilCount));
                                holder.price1.setText(String.valueOf(pencilPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(pencilCount);
                                price1.add(pencilPrice);
                            }
                            else if(position==3)
                            {
                                holder.qty1.setText(String.valueOf(eraserCount));
                                holder.price1.setText(String.valueOf(eraserPrice));

                                sr1.add(sr.get(position));
                                item1.add(item.get(position));
                                data1.add(eraserCount);
                                price1.add(eraserPrice);

                            }


                        }
                    });

                    return view;


                }            

            }

        }
package com.demostudies;

        import android.app.Activity;
        import android.os.Bundle;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.BaseAdapter;
        import android.widget.ListView;
        import android.widget.TextView;

        import java.util.ArrayList;


        public class Trial extends Activity {
            ListView listnew;


            ArrayList<Integer> sr1;
            ArrayList<String> item1;
            ArrayList<Integer> data;
            ArrayList<Integer> price;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.trial);
                data = new ArrayList<>();
                price = new ArrayList<>();
                listnew = (ListView) findViewById(R.id.newlist);

                Bundle bundle = getIntent().getExtras();

                sr1 = bundle.getIntegerArrayList("sr");
                item1 = bundle.getStringArrayList("item");
                data = bundle.getIntegerArrayList("qty");
                price = bundle.getIntegerArrayList("price");

                ArrayList<Integer> qty = new ArrayList<>();
                ArrayList<String> name = new ArrayList<>();
                ArrayList<Integer> srn = new ArrayList<>();
                ArrayList<Integer> ps = new ArrayList<>();
                for(int i=0;i<data.size();i++){
                    if(data.get(i)>0){
                        qty.add(data.get(i));
                        name.add(item1.get(i));
                        srn.add(sr1.get(i));
                        ps.add(price.get(i));
                    }
                }

                sr1.clear();
                sr1.addAll(srn);
                item1.clear();
                item1.addAll(name);
                data.clear();
                data.addAll(qty);
                price.clear();
                price.addAll(ps);
                Custom_Trial ct = new Custom_Trial(this, sr1, item1, data, price);

                listnew.setAdapter(ct);

            }

            public class Custom_Trial extends BaseAdapter {
                Activity a;

                ArrayList<Integer> sr1;
                ArrayList<String> item1;
                ArrayList<Integer> data;
                ArrayList<Integer> price;

                public Custom_Trial(Activity a, ArrayList<Integer> sr1, ArrayList<String> item1, ArrayList<Integer> data, ArrayList<Integer> price) {
                    this.a = a;
                    this.sr1 = sr1;
                    this.item1 = item1;
                    this.data = data;
                    this.price = price;
                }

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

                @Override
                public Object getItem(int position) {
                    return data.get(position);
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }
                public class Holder{
                    TextView sr,it,qty,amt;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    Holder holder=new Holder();
                    LayoutInflater li=a.getLayoutInflater();
                    View view=li.inflate(R.layout.customtrial,parent,false);
                    holder.sr=(TextView)view.findViewById(R.id.head1);
                    holder.it=(TextView)view.findViewById(R.id.head2);
                    holder.qty=(TextView)view.findViewById(R.id.head3);
                    holder.amt=(TextView)view.findViewById(R.id.head4);

                    holder.sr.setText(String.valueOf(sr1.get(position)));
                    holder.it.setText(item1.get(position));
                    holder.qty.setText(String.valueOf(data.get(position)));
                    holder.amt.setText(String.valueOf(price.get(position)));



                    return view;
                }
            }

        }
        package com.demostudies;

        import android.app.Activity;
        import android.content.Intent;
        import android.os.Bundle;
        import android.support.v7.widget.SearchView;
        import android.view.View;
        import android.widget.Button;
        import android.widget.ListView;

        import java.util.ArrayList;
        import java.util.LinkedHashSet;
        import java.util.Set;


        import com.demostudies.adapter.Custom;


        public class MainActivityList extends Activity {

            Button show;
            ListView list_item;
            private ArrayList<Integer> sr;
            private ArrayList<String> item;
            private ArrayList<Integer> quantity;
            private ArrayList<Integer> price;


            private ArrayList<Integer> sr1;
            private ArrayList<String> item1;
            private ArrayList<Integer> price1;
            private ArrayList<Integer> data1;
            SearchView searchView;
            private ArrayList<String> filterlist;
            public Custom custom;

            public int bookCount = 0;
            public int penCount = 0;
            public int pencilCount = 0;
            public int eraserCount=0;

            public int bookPrice = 0;
            public int penPrice = 0;
            public int pencilPrice = 0;
            public int eraserPrice=0;



            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main_list);


                list_item = (ListView) findViewById(R.id.listdetails);



                show=(Button)findViewById(R.id.btnview);
                sr = new ArrayList<>();
                item = new ArrayList<>();
                quantity = new ArrayList<>();
                price = new ArrayList<>();

                sr1 = new ArrayList<>();
                item1 = new ArrayList<>();
                data1= new ArrayList<>();
                price1= new ArrayList<>();

                filterlist = new ArrayList<>();
                item = filterlist;


                sr.add(1);
                sr.add(2);
                sr.add(3);
                sr.add(4);

                item.add("Book");
                item.add("pen");
                item.add("pencil");
                item.add("Eraser");


                quantity.add(0);
                quantity.add(0);
                quantity.add(0);
                quantity.add(0);


                price.add(20);
                price.add(30);
                price.add(5);
                price.add(5);


                Custom c = new Custom(this, sr, item, quantity, price,sr1,item1,data1,price1);
                list_item.setAdapter(c);

                show.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(MainActivityList.this,Trial.class);
                        Set<Integer> s = new LinkedHashSet<>();
                        s.addAll(sr);
                        sr.clear();
                        sr.addAll(s);

                        Set<String> ss = new LinkedHashSet<>();
                        ss.addAll(item);
                        item.clear();
                        item.addAll(ss);

                        data1.clear();
                        price1.clear();

                        for(Integer srn: sr){
                            if(srn==1){
                                data1.add(bookCount);
                                price1.add(bookPrice);
                            }

                            if(srn==2){
                                data1.add(penCount);
                                price1.add(penPrice);
                            }

                            if(srn==3){
                                data1.add(pencilCount);
                                price1.add(pencilPrice);
                            }

                            if(srn==4){
                                data1.add(eraserCount);
                                price1.add(eraserPrice);
                            }
                        }


                        intent.putExtra("sr",sr);
                        intent.putExtra("item",item);
                        intent.putExtra("qty",data1);
                        intent.putExtra("price",price1);
                        startActivity(intent);
                    }
                });

            }

        }
 package com.demostudies.adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import com.demostudies.MainActivityList;
import com.demostudies.R;
import java.util.ArrayList;
public class Custom  extends BaseAdapter {

MainActivityList a;
public ArrayList<Integer> sr;
public ArrayList<String> item;
public ArrayList<Integer> quantity;
public ArrayList<Integer> price;


public ArrayList<Integer> sr1;
public ArrayList<String> item1;
public ArrayList<Integer> data1;
public ArrayList<Integer> price1;
public ArrayList<String> filterlist;

private String data, pricedata;

public Custom(MainActivityList a, ArrayList<Integer> sr,    ArrayList<String> item, ArrayList<Integer> quantity, ArrayList<Integer> price, ArrayList<Integer> sr1, ArrayList<String> item1, ArrayList<Integer> data1, ArrayList<Integer> price1) {
    this.a = a;
    this.sr = sr;
    this.item = item;
    this.quantity = quantity;
    this.price = price;
    this.sr1 = sr1;
    this.item1 = item1;
    this.data1 = data1;
    this.price1 = price1;
}



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

@Override
public Object getItem(int position) {
    return item.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}


public class Holder{
    TextView sr1,item1,qty1,price1;
    Button pl,min;

}


@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final Holder holder=new Holder();
    LayoutInflater li=a.getLayoutInflater();
    final View view=li.inflate(R.layout.customlist,parent,false);

    holder.sr1=(TextView)view.findViewById(R.id.s_no);
    holder.item1=(TextView)view.findViewById(R.id.i_name);
    holder.qty1=(TextView)view.findViewById(R.id.qty);
    holder.price1=(TextView)view.findViewById(R.id.pr);
    holder.pl=(Button) view.findViewById(R.id.pl);
    holder.min=(Button)view.findViewById(R.id.min);


    holder.sr1.setText(String.valueOf(sr.get(position)));
    holder.item1.setText(item.get(position));
    holder.qty1.setText(String.valueOf(quantity.get(position)));
    holder.price1.setText(String.valueOf(price.get(position)));


    holder.pl.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (position) {
                case 0:
                    if (a.bookCount >= 0) {
                        a.bookCount++;
                        a.bookPrice = a.bookPrice + 20;
                        sr.get(position);
                        item.get(position);

                    }
                    break;

                case 1:
                    if (a.penCount >= 0) {
                        a.penCount++;
                        a.penPrice += 30;

                        sr.get(position);
                        item.get(position);

                    }
                    break;
                case 2:
                    if (a.pencilCount >= 0) {
                        a.pencilCount++;
                        a.pencilPrice += 5;

                        sr.get(position);
                        item.get(position);

                    }
                    break;
                case 3:
                    if(a.eraserCount>=0){
                        a.eraserCount++;
                        a.eraserPrice +=5;

                        sr.get(position);
                        item.get(position);


                    }
                    break;
            }
            if(position==0)
            {
                holder.qty1.setText(String.valueOf(a.bookCount));
                holder.price1.setText(String.valueOf(a.bookPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.bookCount);
                price1.add(a.bookPrice);
            }
            else if(position==1)
            {
                holder.qty1.setText(String.valueOf(a.penCount));
                holder.price1.setText(String.valueOf(a.penPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.penCount);
                price1.add(a.penPrice);
            }
            else if(position==2)
            {
                holder.qty1.setText(String.valueOf(a.pencilCount));
                holder.price1.setText(String.valueOf(a.pencilPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.pencilCount);
                price1.add(a.pencilPrice);
            }
            else if(position==3)
            {
                holder.qty1.setText(String.valueOf(a.eraserCount));
                holder.price1.setText(String.valueOf(a.eraserPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.eraserCount);
                price1.add(a.eraserPrice);

            }


        }
    });





    holder.min.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (position) {
                case 0:
                    if (a.bookCount > 0) {
                        a.bookCount--;
                        a.bookPrice -= 20;

                        sr.get(position);
                        item.get(position);

                    }
                    break;
                case 1:
                    if (a.penCount > 0) {
                        a.penCount--;
                        a.penPrice -= 30;

                        sr.get(position);
                        item.get(position);

                    }
                    break;

                case 2:
                    if (a.pencilCount > 0) {
                        a.pencilCount--;
                        a.pencilPrice -= 5;

                        sr.get(position);
                        item.get(position);

                    }
                    break;
                case 3:
                    if(a.eraserCount > 0){
                        a.eraserCount--;
                        a.eraserPrice-=5;

                        sr.get(position);
                        item.get(position);

                    }
                    break;
            }

            if(position==0)
            {
                holder.qty1.setText(String.valueOf(a.bookCount));
                holder.price1.setText(String.valueOf(a.bookPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.bookCount);
                price1.add(a.bookPrice);
            }
            else if(position==1)
            {
                holder.qty1.setText(String.valueOf(a.penCount));
                holder.price1.setText(String.valueOf(a.penPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.penCount);
                price1.add(a.penPrice);
            }
            else if(position==2)
            {
                holder.qty1.setText(String.valueOf(a.pencilCount));
                holder.price1.setText(String.valueOf(a.pencilPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.pencilCount);
                price1.add(a.pencilPrice);
            }
            else if(position==3)
            {
                holder.qty1.setText(String.valueOf(a.eraserCount));
                holder.price1.setText(String.valueOf(a.eraserPrice));

                sr1.add(sr.get(position));
                item1.add(item.get(position));
                data1.add(a.eraserCount);
                price1.add(a.eraserPrice);

            }


        }
    });

    return view;
}
}
        package com.demostudies;
        import android.app.Activity;
        import android.os.Bundle;
        import android.widget.ListView;
        import com.demostudies.adapter.Custom_Trial;
        import java.util.ArrayList;

        public class Trial extends Activity {
            ListView listnew;
            ArrayList<Integer> sr1;
            ArrayList<String> item1;
            ArrayList<Integer> data;
            ArrayList<Integer> price;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.trial);
                data = new ArrayList<>();
                price = new ArrayList<>();
                listnew = (ListView) findViewById(R.id.newlist);

                Bundle bundle = getIntent().getExtras();

                sr1 = bundle.getIntegerArrayList("sr");
                item1 = bundle.getStringArrayList("item");
                data = bundle.getIntegerArrayList("qty");
                price = bundle.getIntegerArrayList("price");

                ArrayList<Integer> qty = new ArrayList<>();
                ArrayList<String> name = new ArrayList<>();
                ArrayList<Integer> srn = new ArrayList<>();
                ArrayList<Integer> ps = new ArrayList<>();
                for(int i=0;i<data.size();i++){
                    if(data.get(i)>0){
                        qty.add(data.get(i));
                        name.add(item1.get(i));
                        srn.add(sr1.get(i));
                        ps.add(price.get(i));
                    }
                }

                sr1.clear();
                sr1.addAll(srn);
                item1.clear();
                item1.addAll(name);
                data.clear();
                data.addAll(qty);
                price.clear();
                price.addAll(ps);
                Custom_Trial ct = new Custom_Trial(this, sr1, item1, data, price);
                listnew.setAdapter(ct);

            }
        }
package com.demostudies.adapter;
    import android.app.Activity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.TextView;
    import com.demostudies.R;
    import java.util.ArrayList;

    public class Custom_Trial extends BaseAdapter {
        Activity a;
        ArrayList<Integer> sr1;
        ArrayList<String> item1;
        ArrayList<Integer> data;
        ArrayList<Integer> price;

        public Custom_Trial(Activity a, ArrayList<Integer> sr1, ArrayList<String> item1, ArrayList<Integer> data, ArrayList<Integer> price) {
            this.a = a;
            this.sr1 = sr1;
            this.item1 = item1;
            this.data = data;
            this.price = price;
        }

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

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }
        public class Holder{
            TextView sr,it,qty,amt;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder holder=new Holder();
            LayoutInflater li=a.getLayoutInflater();
            View view=li.inflate(R.layout.customtrial,parent,false);
            holder.sr=(TextView)view.findViewById(R.id.head1);
            holder.it=(TextView)view.findViewById(R.id.head2);
            holder.qty=(TextView)view.findViewById(R.id.head3);
            holder.amt=(TextView)view.findViewById(R.id.head4);

            holder.sr.setText(String.valueOf(sr1.get(position)));
            holder.it.setText(item1.get(position));
            holder.qty.setText(String.valueOf(data.get(position)));
            holder.amt.setText(String.valueOf(price.get(position)));

            return view;
        }
    }