问:
To get data in listview
When i click on view button it shows 4 fields in listview-Sr,Item,Qty,Prize.
I am able to get data in Listview but problem is that when i increment 3 times it shows all value of incrementation.Suppose for 1 item price is 5.It shows
1-5,2-10,3-15.But i directly want to show 3-15 if it is incremented 3 times.I have added xml too.Thanks for help in advance.
Following is my code-

```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>
```

答:
Changes with max quantity:
MainActivityList.class

```<code>        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);
                    }
                });

            }

        }
</code>```

Custom.class

```<code> 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;
}
}
</code>```

Trial.class

```<code>        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);

            }
        }
</code>```

Custom_Trial.class

```<code>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;
        }
    }
</code>```

Title: To get data in listview

Body:
When i click on view button it shows 4 fields in listview-Sr,Item,Qty,Prize.
I am able to get data in Listview but problem is that when i increment 3 times it shows all value of incrementation.Suppose for 1 item price is 5.It shows
1-5,2-10,3-15.But i directly want to show 3-15 if it is incremented 3 times.I have added xml too.Thanks for help in advance.
Following is my code-

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>

Body:
Changes with max quantity:
MainActivityList.class

        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);
                    }
                });

            }

        }

Custom.class

 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;
}
}

Trial.class

        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);

            }
        }

Custom_Trial.class

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;
        }
    }


来源: stackexchange

问:
How to get values of multiple textboxes generated dynamically?
I have a button called 'AddTextArea', on clicking, I get new text area, but how can I get the values that I have entered in the new text areas?

I tried like this-

```<code>var x= document.getElementById("div_quotes").value;
</code>```

but it's not working.
Please help, as I am new to JS, thanks in advance.

  <form method="post">

    <input type="button" value="Add Text Area" onClick="addTextArea();">
    <input type="submit" name="submitted">
  </form>

```

答:
You can add a CSS Class to the new text area that is generated and get the data using

var x = document.getElementsByClassName("dynamicTxtArea")```
</div>
</div>
</p>

<p>I have added the class to the Text area that is being dynamically generated. Please check the code below.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><html>
<head>
    <script type="text/javascript">
        function addTextArea(){
            div.innerHTML += "<textarea name='new_quote[]' class='dynamicTxtArea'/>";
            div.innerHTML += "\n<br />";
        }
    </script>
</head>
<body>
  <form method="post">
    <!--<input type="text" name="text_new_author" /><br />-->
    <div id="div_quotes"></div>
    <input type="button" value="Add Text Area" onClick="addTextArea();">
    <input type="submit" name="submitted">
  </form>
</body>
</html></code>```

ContentLicense: CC BY-SA 3.0

Body:
I have a button called 'AddTextArea', on clicking, I get new text area, but how can I get the values that I have entered in the new text areas?

I tried like this-

var x= document.getElementById("div_quotes").value;

but it's not working.
Please help, as I am new to JS, thanks in advance.

  <form method="post">

    <input type="button" value="Add Text Area" onClick="addTextArea();">
    <input type="submit" name="submitted">
  </form>

Body:
You can add a CSS Class to the new text area that is generated and get the data using

var x = document.getElementsByClassName("dynamicTxtArea")

I have added the class to the Text area that is being dynamically generated. Please check the code below.

<html>
<head>
    <script type="text/javascript">
        function addTextArea(){
            div.innerHTML += "<textarea name='new_quote[]' class='dynamicTxtArea'/>";
            div.innerHTML += "\n<br />";
        }
    </script>
</head>
<body>
  <form method="post">
    <!--<input type="text" name="text_new_author" /><br />-->
    <div id="div_quotes"></div>
    <input type="button" value="Add Text Area" onClick="addTextArea();">
    <input type="submit" name="submitted">
  </form>
</body>
</html>


问:
php preg_replace remove the last new line character?
I have following string in my database and i want to remove the "\r\n" at the end of the string, i tried number of times but all failed

for example, see below

```<code><?php

$text = 'Am a 44 year old divorced lady with two adult sons. Having been single for 15years and dedicating my life to my two boys, am ready now to find love and companionship with a loving caring honest man with humane values\r\n\r\nThough 44 I look much younger. Look forward to meeting a like minded honest man and share the rest of our  journey of life together with mutual understanding and complement each other.       \r\n\r\nWill be happy to forward a photograph after initial dialogue\r\n';

echo $essay = preg_replace("/(\\r\\n)$/", ' ', $text);
echo preg_replace("/\=\r\n$/", " ", $text);
</code>```

I am testing this with

http://phptester.net/

but unable to get expected output as below

```<code>$text = 'Am a 44 year old divorced lady with two adult sons. Having been single for 15years and dedicating my life to my two boys, am ready now to find love and companionship with a loving caring honest man with humane values\r\n\r\nThough 44 I look much younger. Look forward to meeting a like minded honest man and share the rest of our  journey of life together with mutual understanding and complement each other.       \r\n\r\nWill be happy to forward a photograph after initial dialogue';
</code>```

答:
The \r\n you want to remove are not CR+LF symbols, but a string of 4 chars because inside single quoted string literals, \ is a literal backslash. So, your string ends with \, r, \, n. To match a literal \ with a regex, you need to use 4 backslashes, not 2.

See the PHP demo:

```<code>$text = 'Am a 44 year old divorced lady with two adult sons. Having been single for 15years and dedicating my life to my two boys, am ready now to find love and companionship with a loving caring honest man with humane values\r\n\r\nThough 44 I look much younger. Look forward to meeting a like minded honest man and share the rest of our  journey of life together with mutual understanding and complement each other.       \r\n\r\nWill be happy to forward a photograph after initial dialogue\r\n';
echo $essay = preg_replace("/\\\\r\\\\n$/", '', $text);
</code>```

Note that you may just check if a string ends with \r\n, and then substr it.

Body:
I have following string in my database and i want to remove the "\r\n" at the end of the string, i tried number of times but all failed

for example, see below

<?php

$text = 'Am a 44 year old divorced lady with two adult sons. Having been single for 15years and dedicating my life to my two boys, am ready now to find love and companionship with a loving caring honest man with humane values\r\n\r\nThough 44 I look much younger. Look forward to meeting a like minded honest man and share the rest of our  journey of life together with mutual understanding and complement each other.       \r\n\r\nWill be happy to forward a photograph after initial dialogue\r\n';

echo $essay = preg_replace("/(\\r\\n)$/", ' ', $text);
echo preg_replace("/\=\r\n$/", " ", $text);

I am testing this with

http://phptester.net/

but unable to get expected output as below

$text = 'Am a 44 year old divorced lady with two adult sons. Having been single for 15years and dedicating my life to my two boys, am ready now to find love and companionship with a loving caring honest man with humane values\r\n\r\nThough 44 I look much younger. Look forward to meeting a like minded honest man and share the rest of our  journey of life together with mutual understanding and complement each other.       \r\n\r\nWill be happy to forward a photograph after initial dialogue';

Body:
The \r\n you want to remove are not CR+LF symbols, but a string of 4 chars because inside single quoted string literals, \ is a literal backslash. So, your string ends with \, r, \, n. To match a literal \ with a regex, you need to use 4 backslashes, not 2.

See the PHP demo:

$text = 'Am a 44 year old divorced lady with two adult sons. Having been single for 15years and dedicating my life to my two boys, am ready now to find love and companionship with a loving caring honest man with humane values\r\n\r\nThough 44 I look much younger. Look forward to meeting a like minded honest man and share the rest of our  journey of life together with mutual understanding and complement each other.       \r\n\r\nWill be happy to forward a photograph after initial dialogue\r\n';
echo $essay = preg_replace("/\\\\r\\\\n$/", '', $text);

Note that you may just check if a string ends with \r\n, and then substr it.


问:
How to implement role-based Authorization for Python REST API?
The basic architecture of my application is React front-end consuming a RESTful API sitting on top of a polyglot storage layer.

Front-end:

React consuming APIs

Back-end:

Python

Flask

Authentication

Auth0+OKTA

Everything is working great. However, I need to have different roles for the users. In other words, I need to control the actions that a user can perform on a resource based on the role.

Example:

-User A wants to add a new user

-He has a token in his request, so I know User A is Authenticated

-Now I need to make sure he can in fact add users base on his role.

I don't want to hard-code the user roles as suggested in other solutions, and I would like to allow for custom roles to be added.

Also, I want to be respectful of people's time, so if there is a resource that addresses my concern, please feel free to point me to it.

These are my questions:

 1. Are there any best practices for implementing what I am trying to accomplish?

 2. Could you point me to examples or tutorials discussing authorization(not authentication)?

 3. Do I check at each service call if the authenticated user can also perform the action or do I provide the roles in some form after authorization, so a service request contains both the authentication and authorization token?(this seems pretty easy to hack so I am guessing no...)

If I sound confused on the topic of authorization, it is because I am. Please feel free to point me to any resource that have been helpful to you.

Thank you in advance for taking the time to help! I really appreciate it.

答:
You can use a framework like Yosai that is based on Apache Shiro.

These are some features:

Enables Role-Based Access Control policies through permission-level and role-level access control

Two-Factor Authentication, featuring Time-based One-Time Passwords

Native Support for Caching and Serialization

Event-driven Processing

Ready for Web Integration


问:
Cannot append to textarea after clearing value
I have a dropdown select that appends to a text area on change.  I set a simple button to clear it out which works but afterwords I cannot re-append from the dropdown select.

Fiddle: https://jsfiddle.net/kreza/noy5gqfL/6/

jquery snippet:

```<code>$('#criteriaSelect').change(function () {
    $('#inputCriteria').append((this.value + ';' + '\n'));
});
$('#clearTextArea').click(function () {
    $('#inputCriteria').val('');
});
</code>```

What am I doing wrong?

答: Try this method $('#inputCriteria').empty();</p>

Body:
I have a dropdown select that appends to a text area on change.  I set a simple button to clear it out which works but afterwords I cannot re-append from the dropdown select.

Fiddle: https://jsfiddle.net/kreza/noy5gqfL/6/

jquery snippet:

$('#criteriaSelect').change(function () {
    $('#inputCriteria').append((this.value + ';' + '\n'));
});
$('#clearTextArea').click(function () {
    $('#inputCriteria').val('');
});

What am I doing wrong?


问:
Material-UI: How to set height of a div equal to appBar's height
I need to set the Drawer padding-top equal to the appBar height.

I can reference the appBar through getMuiTheme function, but I am not sure how to pass this down my child Drawer?

```<code>render(){
    return(
        <div>
            <Header/>
            <div style= {{"paddingTop": "64px", "minHeight": "400px", "paddingLeft": "256px"}}>
                <div style = {{"margin": "48px 72px", "height": "600px"}}>
                    My component is here

                     {this.props.children}
                </div>

            </div>
            <Menu/>

        </div>
    );
}
</code>```

I need to reference the appBar's height dynamically so whenever I change my appBar height I don't have to worry about the paddingTop here anymore.

Thanks,

答: Consider using React-Measure to get the height of the appBar and save it in the component's state. You can use that height to set the height of the div.</p>

Body:
I need to set the Drawer padding-top equal to the appBar height.

I can reference the appBar through getMuiTheme function, but I am not sure how to pass this down my child Drawer?

render(){
    return(

                    My component is here

                     {this.props.children}

            <Menu/>

    );
}

I need to reference the appBar's height dynamically so whenever I change my appBar height I don't have to worry about the paddingTop here anymore.

Thanks,


问:
WriteableBitmap in .NET 4
I have got a problem: I would like to use a method Render() for WriteableBitmap object. However, as I noticed, the method is not available without using a Silverlight assembly System.Windows.dll. I need to use RenderTargetBitmap in my project (PresentationCore assembly for standard .net). Here is the problem - there are definitions of some classes in both assemblies, thus they are in conflict.

Basically, I need to add some stuff to Bgra32 bitmap. However, RenderTargetBitmap works only with Pbgra32 ones. I found that using WriteableBitmap to render would be nice. Maybe I am wrong?

Do you have any ideas?

Thank you in advance for the reply!

Cheers

答:
I know this was asked a while ago, but it came up in a search I did for a related issue so I thought I would leave a brief answer for anyone else who stumbled upon it.

Including both the Silverlight and WPF assemblies is NOT a good idea. Pretty much everything you need from Silverlight will be in WPF in one way or another, so unless you are doing a Silverlight project (and not using WPF assemblies) don't include them!

For your problem, converting between Pbgra and Bgra is not particularly difficult and is described here:

http://www.i-programmer.info/programming/wpf-workings/538-rendertargetbitmap-visual-vector-to-bitmap.html.

Besides, RenderTargetBitmap does sort of the same thing as the Render method so you would be better off trying to use that on it's own.

ContentLicense: CC BY-SA 2.5

Title: WriteableBitmap in .NET 4


问:
Get Element ID - JavaScript
I know the data-id from the li element, but now i want the id value of the li element. How can I get this? Tried:

```<code> var id = $('li[data-id="KnSubject[StId]"]').id;
 console.log(id); // UNDEFINED
</code>```

Html Code:

```<code><li role="treeitem" data-jstree="{"icon" : "glyphicon glyphicon-pencil"}" data-id="KnSubject[StId]" data-values="null" aria-selected="true" aria-level="3" aria-labelledby="j1_4_anchor" id="j1_4" class="jstree-node  jstree-leaf"><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" tabindex="-1" id="j1_4_anchor"><i class="jstree-icon jstree-themeicon glyphicon glyphicon-pencil jstree-themeicon-custom" role="presentation"></i>Type dossieritem (StId)</a></li>
</code>```

答:
Use attr function.

var elem = $('li[data-id="KnSubject[StId]"]');
console.log(elem.attr('id'));```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li role="treeitem" data-jstree="{"icon" : "glyphicon glyphicon-pencil"}" data-id="KnSubject[StId]" data-values="null" aria-selected="true" aria-level="3" aria-labelledby="j1_4_anchor" id="j1_4" class="jstree-node  jstree-leaf"><i class="jstree-icon jstree-ocl" role="presentation"></i><i class="jstree-icon jstree-themeicon glyphicon glyphicon-pencil jstree-themeicon-custom" role="presentation"></i>Type dossieritem (StId)</li></code>```

Title: Get Element ID - JavaScript

Body:
I know the data-id from the li element, but now i want the id value of the li element. How can I get this? Tried:

 var id = $('li[data-id="KnSubject[StId]"]').id;
 console.log(id); // UNDEFINED

Html Code:

Type dossieritem (StId)

Body:
Use attr function.

var elem = $('li[data-id="KnSubject[StId]"]');
console.log(elem.attr('id'));

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li role="treeitem" data-jstree="{&quot;icon&quot; : &quot;glyphicon glyphicon-pencil&quot;}" data-id="KnSubject[StId]" data-values="null" aria-selected="true" aria-level="3" aria-labelledby="j1_4_anchor" id="j1_4" class="jstree-node  jstree-leaf"><i class="jstree-icon jstree-ocl" role="presentation"></i><a class="jstree-anchor jstree-clicked" href="#" tabindex="-1" id="j1_4_anchor"><i class="jstree-icon jstree-themeicon glyphicon glyphicon-pencil jstree-themeicon-custom" role="presentation"></i>Type dossieritem (StId)</a></li>