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

答:
Use this Activity:

MainActivityList.class:

```<code>import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MainActivityList extends Activity {

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

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

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

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

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

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

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

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

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

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

}

public class Custom extends BaseAdapter {

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

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

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

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

    }

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

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

        final Model model = models.get(position);

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

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

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

            }
        });

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

        );

        return view;

    }

}
}
</code>```

Trial.class

```<code>            package com.demostudies;

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

        import java.util.ArrayList;

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

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

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

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

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

        }

        class Custom_Trial extends BaseAdapter {

            @Override
            public int getCount() {

                return data.size();
            }

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

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

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

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

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

                return view;
            }
        }
    }
</code>```

Model.class

```<code>    import java.io.Serializable;
    public class Model  implements Serializable

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

        public String getQty() {
            return qty;
        }

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

        public String getItemName() {
            return itemName;
        }

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

        public String getPrice() {
            return price;
        }

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

        public String getSrNo() {
            return srNo;
        }

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

        public String getTotalSum() {
            return totalSum;
        }

        public void setTotalSum(String totalSum) {
            this.totalSum = totalSum;
        }
    }
</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:
Use this Activity:

MainActivityList.class:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MainActivityList extends Activity {

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

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

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

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

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

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

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

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

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

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

}

public class Custom extends BaseAdapter {

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

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

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

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

    }

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

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

        final Model model = models.get(position);

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

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

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

            }
        });

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

        );

        return view;

    }

}
}

Trial.class

            package com.demostudies;

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

        import java.util.ArrayList;

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

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

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

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

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

        }

        class Custom_Trial extends BaseAdapter {

            @Override
            public int getCount() {

                return data.size();
            }

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

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

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

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

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

                return view;
            }
        }
    }

Model.class

    import java.io.Serializable;
    public class Model  implements Serializable

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

        public String getQty() {
            return qty;
        }

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

        public String getItemName() {
            return itemName;
        }

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

        public String getPrice() {
            return price;
        }

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

        public String getSrNo() {
            return srNo;
        }

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

        public String getTotalSum() {
            return totalSum;
        }

        public void setTotalSum(String totalSum) {
            this.totalSum = totalSum;
        }
    }


来源: stackexchange

问:
Angular2 - How can I add HTTP headers to responses my app sends to the browser?
I'm prototyping an Angular2 app at work. The app should run under some company middleware that expects several Link headers in responses it gets from the angular2 app. Unfortunately, I haven't been able to figure out how to add headers to responses that Angular provides out of the box.

To clarify what I mean - when I send a GET Request directly to my Angular app, it sends back a Text/HTML response that a browser can render into an SPA. I would like to add headers to this response, and can't figure out how. The closest I've found is the discussion here: Angular2 - set headers for every request

This sounds like a duplicate, but having looked through similar questions, I've found how to add headers to Responses I generate explicitly with an HTTP object from the HttpModule, but not how to attach headers to the Responses that Angular creates out-of-the-box. I'd love to use something like an HTTP Interceptor that just attaches headers to every response my app sends out, but it doesn't look like Angular2 will have interceptors until release 4.1.

Edit: Things I've tried:

Adding a provider for Http ResponseOptions in my (main) AppModule that adds headers to responses

This adds the header to all responses I receive from http requests that my app receives from the HttpModule, but doesn't add the header to responses that my app itself sends to outside services.

Edit 2: I misunderstood where my Angular app ends and where the server hosting it begins. Headers like this can be added in the server - for my simple example, I needed to configure the webpack-dev-server. See the accepted answer below.

答:
I don't know the angular2-webpack-starter, but I guess it's just a command line tool easy development of your Angular application. So it just serves your JavaScript, HTML and assets. It's not the application itself. The Angular application runs in a browser and serves as a client of your backend. So you need another server that serves your backend application and all your XHR calls will go to this backend. When you deploy your application, it will probably not run in the angular2-webpack-starter, but in some more advanced HTTP server such as Apache HTTPD or nginx.

Then you need to create a custom Http service (extending angular's own Http service) or XHRBackend. It has access to Request and Response object and can add extra headers there.

ContentLicense: CC BY-SA 3.0


问:
Returning reference to local variable without trivial conversion
I am quite a newbie to the C++ programming, but this question keeps on spinning in my head. I understand that returning reference to a local variable in a function is illegal, i.e. compiling this code snippet:

```<code>inline int& funref() {
    int    a = 8;
    return a;     // not OK!
}
</code>```

results in a warning from the compiler and then a runtime error. But then, why does this piece of code get compiled without any warnings and run without error?

```<code>inline int& funref() {
    int  a    = 8;
    int& refa = a;
    return refa;   // OK!
}

int main() {
    int& refa = funref();
    cout << refa;
}
</code>```

My compiler is g++ on Linux Fedora platform.

答:
The reason why you can't return a reference to a local variable is because the local variable will get wiped when your function returns. Simply put, the compiler prevents you from referencing garbage data.

However, the compiler isn't bulletproof (as shown in your example #2).

It does work for retrieving a singleton instance, though.

```<code>inline int& funref()
    {
    static int* p_a = nullptr;
    if (nullptr == p_a)
        p_a = new int(8);

    return *p_a;
    }
</code>```

this case is valid because the memory pointed by p_a remains valid after the function returns.

Body:
I am quite a newbie to the C++ programming, but this question keeps on spinning in my head. I understand that returning reference to a local variable in a function is illegal, i.e. compiling this code snippet:

inline int& funref() {
    int    a = 8;
    return a;     // not OK!
}

results in a warning from the compiler and then a runtime error. But then, why does this piece of code get compiled without any warnings and run without error?

inline int& funref() {
    int  a    = 8;
    int& refa = a;
    return refa;   // OK!
}

int main() {
    int& refa = funref();
    cout << refa;
}

My compiler is g++ on Linux Fedora platform.

Body:
The reason why you can't return a reference to a local variable is because the local variable will get wiped when your function returns. Simply put, the compiler prevents you from referencing garbage data.

However, the compiler isn't bulletproof (as shown in your example #2).

It does work for retrieving a singleton instance, though.

inline int& funref()
    {
    static int* p_a = nullptr;
    if (nullptr == p_a)
        p_a = new int(8);

    return *p_a;
    }

this case is valid because the memory pointed by p_a remains valid after the function returns.


问:
In unity tag is not found in first drag
I am making a simple drag and drop unity game. When I drag the object for the first time it does not give score but when I drag it once again it gives score even if I am dropping at the wrong place. I am using tag to match desired objects</p>

```<code>using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;

public class sh_score : MonoBehaviour {
    static int score = 0;
    public Text scoreText;

    public GameObject ans_circle;
    public GameObject tag_circle;
    public GameObject tag_rectangle;
    public GameObject ans_rectangle;
    public GameObject ans_triangle;
    public GameObject tag_triangle;
    public GameObject ans_square;
    public GameObject tag_square;
    public GameObject ans_star;
    public GameObject tag_star;

    void Start()
    {
        score = score;

        if( (ans_circle == null || tag_circle == null) || (ans_rectangle  == null || tag_rectangle == null)|| (ans_square == null || tag_square == null) || (ans_triangle == null || tag_triangle == null)|| (ans_star == null || tag_star == null))
        {
            ans_circle = GameObject.FindGameObjectWithTag("ans_circle");
            if (ans_circle != null)
            { Debug.Log("ans Find"); }

            tag_circle = GameObject.FindGameObjectWithTag("circle");
            if (tag_circle != null)
            {
                Debug.Log("circle");
            }

            checkTagPlace();

            ans_rectangle = GameObject.FindGameObjectWithTag("ans_rectangle");
            if (ans_rectangle != null)
            { Debug.Log("ans Find"); }

            tag_rectangle = GameObject.FindGameObjectWithTag("rectangle");
            if (tag_circle != null)
            {
                Debug.Log("rectangle");
            }

            ans_triangle = GameObject.FindGameObjectWithTag("ans_triangle");
            if (ans_triangle != null)
            { Debug.Log("ans Find"); }

            tag_triangle = GameObject.FindGameObjectWithTag("triangle");
            if (tag_triangle != null)
            {
                Debug.Log("triangle");
            }

            ans_star = GameObject.FindGameObjectWithTag("ans_star");
            if (ans_star != null)
            { Debug.Log("ans Find"); }

            tag_star = GameObject.FindGameObjectWithTag("star");
            if (tag_star != null)
            {
                Debug.Log("star");
            }

            ans_square = GameObject.FindGameObjectWithTag("ans_square");
            if (ans_square != null)
            { Debug.Log("ans Find"); }

            tag_square = GameObject.FindGameObjectWithTag("square");
            if (tag_square != null)
            {
                Debug.Log("square");
            }
        }
    }

    void update()
    {
        scoreText.text = score.ToString();
    }

    public void IncrementScore()
    {
        score = score + 9;
        score++;
        scoreText.text = "Score: " + score;
    }

    public void checkTagPlace()
    {
        Debug.Log("check function run");
        float circle_postion = tag_circle.transform.position.x;
        float circle_Tag_positon = ans_circle.transform.position.x;
        float triangle_position = tag_triangle.transform.position.x;
        float triangle_Tag_positon = ans_triangle.transform.position.x;
        float square_postion = tag_square.transform.position.x;
        float square_Tag_positon = ans_square.transform.position.x;
        float star_postion = tag_star.transform.position.x;
        float star_Tag_positon = ans_star.transform.position.x;
        float rectangle_position = tag_rectangle.transform.position.x;
        float rectangle_Tag_positon = ans_rectangle.transform.position.x;
        if ((ans_circle.transform.position.x == tag_circle.transform.position.x))
        {
            Debug.Log("found position");
            IncrementScore();
        }
        else if ((ans_rectangle.transform.position.x == tag_rectangle.transform.position.x))
        {
            IncrementScore();
        }
        else if ((ans_square.transform.position.x == tag_square.transform.position.x))
        {
            IncrementScore();
        }
        else if (ans_triangle.transform.position.x == tag_triangle.transform.position.x)
        {
            IncrementScore();
        }

        else if (ans_star.transform.position.x == tag_star.transform.position.x)
        {
            IncrementScore();
        }
    }
}
</code>```

答:
I believe your problem might be here:

```<code>if(ans_rectangle.transform.position.x == tag_rectangle.transform.position.x)
</code>```

When you check to see if these positions (and the other if statements like this one) are equal, you are checking if they're exactly equal. Unless you have some controller which is discretizing the movements of your shapes, thats almost never going to happen.

I believe what you want is really something like this:

```<code>float epsilon=.001;
if(Math.abs(ans_rectangle.transform.position.x - tag_rectangle.transform.position.x)<epsilon)
</code>```

Alternatively, you can give colliders to all of your shapes and actually check for collisions between the two shape types, perhaps using layer masks to keep from comparing shapes of dissimilar types.

I understand that this doesn't explain all the behavior you're seeing, but it might explain why it doesn't increment your score the first time.

Since you don't include the code which is enabling the dragging, we can't know if that is the problem or not.

Title: In unity tag is not found in first drag

Body:
I am making a simple drag and drop unity game. When I drag the object for the first time it does not give score but when I drag it once again it gives score even if I am dropping at the wrong place. I am using tag to match desired objects

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;

public class sh_score : MonoBehaviour {
    static int score = 0;
    public Text scoreText;

    public GameObject ans_circle;
    public GameObject tag_circle;
    public GameObject tag_rectangle;
    public GameObject ans_rectangle;
    public GameObject ans_triangle;
    public GameObject tag_triangle;
    public GameObject ans_square;
    public GameObject tag_square;
    public GameObject ans_star;
    public GameObject tag_star;

    void Start()
    {
        score = score;

        if( (ans_circle == null || tag_circle == null) || (ans_rectangle  == null || tag_rectangle == null)|| (ans_square == null || tag_square == null) || (ans_triangle == null || tag_triangle == null)|| (ans_star == null || tag_star == null))
        {
            ans_circle = GameObject.FindGameObjectWithTag("ans_circle");
            if (ans_circle != null)
            { Debug.Log("ans Find"); }

            tag_circle = GameObject.FindGameObjectWithTag("circle");
            if (tag_circle != null)
            {
                Debug.Log("circle");
            }

            checkTagPlace();

            ans_rectangle = GameObject.FindGameObjectWithTag("ans_rectangle");
            if (ans_rectangle != null)
            { Debug.Log("ans Find"); }

            tag_rectangle = GameObject.FindGameObjectWithTag("rectangle");
            if (tag_circle != null)
            {
                Debug.Log("rectangle");
            }

            ans_triangle = GameObject.FindGameObjectWithTag("ans_triangle");
            if (ans_triangle != null)
            { Debug.Log("ans Find"); }

            tag_triangle = GameObject.FindGameObjectWithTag("triangle");
            if (tag_triangle != null)
            {
                Debug.Log("triangle");
            }

            ans_star = GameObject.FindGameObjectWithTag("ans_star");
            if (ans_star != null)
            { Debug.Log("ans Find"); }

            tag_star = GameObject.FindGameObjectWithTag("star");
            if (tag_star != null)
            {
                Debug.Log("star");
            }

            ans_square = GameObject.FindGameObjectWithTag("ans_square");
            if (ans_square != null)
            { Debug.Log("ans Find"); }

            tag_square = GameObject.FindGameObjectWithTag("square");
            if (tag_square != null)
            {
                Debug.Log("square");
            }
        }
    }

    void update()
    {
        scoreText.text = score.ToString();
    }

    public void IncrementScore()
    {
        score = score + 9;
        score++;
        scoreText.text = "Score: " + score;
    }

    public void checkTagPlace()
    {
        Debug.Log("check function run");
        float circle_postion = tag_circle.transform.position.x;
        float circle_Tag_positon = ans_circle.transform.position.x;
        float triangle_position = tag_triangle.transform.position.x;
        float triangle_Tag_positon = ans_triangle.transform.position.x;
        float square_postion = tag_square.transform.position.x;
        float square_Tag_positon = ans_square.transform.position.x;
        float star_postion = tag_star.transform.position.x;
        float star_Tag_positon = ans_star.transform.position.x;
        float rectangle_position = tag_rectangle.transform.position.x;
        float rectangle_Tag_positon = ans_rectangle.transform.position.x;
        if ((ans_circle.transform.position.x == tag_circle.transform.position.x))
        {
            Debug.Log("found position");
            IncrementScore();
        }
        else if ((ans_rectangle.transform.position.x == tag_rectangle.transform.position.x))
        {
            IncrementScore();
        }
        else if ((ans_square.transform.position.x == tag_square.transform.position.x))
        {
            IncrementScore();
        }
        else if (ans_triangle.transform.position.x == tag_triangle.transform.position.x)
        {
            IncrementScore();
        }

        else if (ans_star.transform.position.x == tag_star.transform.position.x)
        {
            IncrementScore();
        }
    }
}

Body:
I believe your problem might be here:

if(ans_rectangle.transform.position.x == tag_rectangle.transform.position.x)

When you check to see if these positions (and the other if statements like this one) are equal, you are checking if they're exactly equal. Unless you have some controller which is discretizing the movements of your shapes, thats almost never going to happen.

I believe what you want is really something like this:

float epsilon=.001;
if(Math.abs(ans_rectangle.transform.position.x - tag_rectangle.transform.position.x)<epsilon)

Alternatively, you can give colliders to all of your shapes and actually check for collisions between the two shape types, perhaps using layer masks to keep from comparing shapes of dissimilar types.

I understand that this doesn't explain all the behavior you're seeing, but it might explain why it doesn't increment your score the first time.

Since you don't include the code which is enabling the dragging, we can't know if that is the problem or not.


问:
Unable to render index.html file from my view folder in angular2
I'm creating a MEAN Stack application where angular has setup in /client folder. I want that when I run npm start command in /client folder it should render index.html file from /views folder, what I'm doing wrong getting this error

Cannot GET /

Folder structure is as follows.

meanApp

----- client (angluar2 setup here but doesn't have an index.html file)

---------- app

----- views

----------index.html

----- routes

----- server.js

Codes in server.js

```<code>var express = require("express");
var path = require("path");
var bodyParser = require("body-parser");

var index =  require('./routes/index');
var tasks = require("./routes/tasks");

var app = express();

//View engines

app.set("views", path.join(__dirname,'views'));

app.set("view engine", 'ejs');

app.engine("html", require("ejs").renderFile);

//Set static folder

app.use(express.static(path.join(__dirname,'client')));

// Body parser

app.use(bodyParser.json());

app.use(bodyParser.urlencoded({extended:false}));

app.use('/', index);

app.use('/index', index);

app.use('/api', tasks);

//listen

app.listen(3000, function(){

    console.log("Server listing @ 3000");

});
</code>```

答:
Here you need to define route for express server like :

```<code>app.set('appPath', 'client'); //this is a folder where your index.html is

app.route('/*')
    .get(function(req, res) {
      res.sendfile(app.get('appPath') + '/index.html');
    });
</code>```

This will cause every call in broweser to render index file.

Body:
I'm creating a MEAN Stack application where angular has setup in /client folder. I want that when I run npm start command in /client folder it should render index.html file from /views folder, what I'm doing wrong getting this error

Cannot GET /

Folder structure is as follows.

meanApp

----- client (angluar2 setup here but doesn't have an index.html file)

---------- app

----- views

----------index.html

----- routes

----- server.js

Codes in server.js

var express = require("express");
var path = require("path");
var bodyParser = require("body-parser");

var index =  require('./routes/index');
var tasks = require("./routes/tasks");

var app = express();

//View engines

app.set("views", path.join(__dirname,'views'));

app.set("view engine", 'ejs');

app.engine("html", require("ejs").renderFile);

//Set static folder

app.use(express.static(path.join(__dirname,'client')));

// Body parser

app.use(bodyParser.json());

app.use(bodyParser.urlencoded({extended:false}));

app.use('/', index);

app.use('/index', index);

app.use('/api', tasks);

//listen

app.listen(3000, function(){

    console.log("Server listing @ 3000");

});

Body:
Here you need to define route for express server like :

app.set('appPath', 'client'); //this is a folder where your index.html is

app.route('/*')
    .get(function(req, res) {
      res.sendfile(app.get('appPath') + '/index.html');
    });

This will cause every call in broweser to render index file.


问:
Including JS variables in CSS Nodejs
I have a JSON file which will bring the style details .i.e. hexadecimal values of various buttons, font-size etc.

Developing the application in ReactJs.

And I want to use those style values in a custom class in React-Bootstrap.
But to define a custom class, a css file is needed.

Question: Any way to define a variable in CSS file which brings the values from JSON?

答:
Any way to define a variable in CSS file which brings the values from JSON?
No, this is not possible with css3.
I haven't worked with react but can't you pass your styles object to component?
If this is not the case why not to use inline style, I don't think performance hit of inline style is that relevant these days.
As a last option you could generate temp file from json and dynamically add it to page.</p>

Title: Including JS variables in CSS Nodejs


问:
I want to search a position in google maps with the searchbox in a prompt
How do I make a prompt in HTML that searches a google maps position? i already have the google maps. And a button that gives me a prompt (with textbox). But how can i search from that textbox my given position?? help me plz

Picture
Like this but now i want a result in google maps.

答:
If you set the location to variables so for example that you get from

```<code>var x = prompt("What is the longitude?");
var y = prompt("What is the latitude?");
</code>```

that way you'll set the location based on the prompts

Body:
If you set the location to variables so for example that you get from

var x = prompt("What is the longitude?");
var y = prompt("What is the latitude?");

that way you'll set the location based on the prompts


问:
Swift optional binding constant names
I am just transitioning from Objective-C to Swift and have been constantly writing the following code for optional binding,

```<code>if let tempX = X {

}
</code>```

My question is I have to do it so often that I need to find a new name for constant every time. What's the way to avoid having a new name tempX for every optional X in the code? Wouldn't something like work?

```<code>if let X = X {

}
</code>```

答:
Yes, you can reuse the same identifier in such bindings. But keep in mind that the redefined, non-optionalX will only be visible inside the if scope.

But if you use a guard statement, the new X may shadow the previous variable (i.e., if previous variable was defined in another scope; otherwise will trigger a compiler error). Some would say this could hurt your code readability.

For further information, please see this related question.

Title: Swift optional binding constant names

Body:
I am just transitioning from Objective-C to Swift and have been constantly writing the following code for optional binding,

if let tempX = X {

}

My question is I have to do it so often that I need to find a new name for constant every time. What's the way to avoid having a new name tempX for every optional X in the code? Wouldn't something like work?

if let X = X {

}


问:
Is there a recommended DTLS library?
Is there a dtls library that you recommended?</p>

答:
I wrote a commentary/guide on how Net-SNMP used OpenSSL to implement DTLS:

http://www.net-snmp.org/wiki/index.php/DTLS_Implementation_Notes

Unfortunately, there are probably a few things incorrect and out of date with it.  But it's still a better starting place because there is very little usable documentation out there at all.

Title: Is there a recommended DTLS library?

ContentLicense: CC BY-SA 2.5


问:
laravel mix build successfully but vue.js new component not working or any changes not appearing
First time i am using vue.js in my laravel app. every-time message appear that laravel mix build successfully but my vie.js comment changes not displaying.

```<code>require('./bootstrap');
Vue.component('example', require('./components/Example.vue'));
Vue.component('my-vuetable', require('./components/MyVuetable.vue'));

const app = new Vue({

el: '#app'

});
</code>```

i forget to run any important command ?

view:

```<code> <div class="content">
        <div class="title m-b-md">
            Laravel
        </div>
        <div id="app">

          <example></example>
        </div>
 </div>
</code>```

Component

<template>

Example Component

 I'm an example component 5

</template>
```

答: in bootstrap.js look for 'X-CSRF-TOKEN': window.Laravel.csrfToken, and comment it out </p>

Body:
First time i am using vue.js in my laravel app. every-time message appear that laravel mix build successfully but my vie.js comment changes not displaying.

require('./bootstrap');
Vue.component('example', require('./components/Example.vue'));
Vue.component('my-vuetable', require('./components/MyVuetable.vue'));

const app = new Vue({

el: '#app'

});

i forget to run any important command ?

view:

            Laravel

          <example></example>

Component

<template>

Example Component

 I'm an example component 5

</template>


问:
How can I associate a particular userID with a particular table view cell?
I am creating an app that has a table view of users that I am pulling down using JSON. The table view is populating with all the information I want, however I am just doing basic information. What I want to happen is a user will click on a table view cell and it will take them to another view controller and in that view controller there will be a more detailed profile view. In my JSON I am getting all of the user information when the table view initially loads like UserID and such, and I want to associate that user ID with each individual table cell so that when they are clicked I can run a php script in the next window to display the profile of the user from the table.</p>

答:
The way I usually do this is to first map the JSON to model objects and use those model objects in the table data source to populate the table view. When a cell is tapped, I do the reverse mapping (from cell to model object) and can forward the model object (or a subset of the model object's information) to the next view controller in prepare(for:sender:). To make this happen, I set up the cell in Interface Builder to trigger a segue to the details view controller on selection.

Example code:

```<code>struct User
{
    let id: String
    let name: String
    // etc.
}

class YourTableViewController: UITableViewController
{
    var users: [User] = []

    override func viewDidLoad() {
        super.viewDidLoad()
        let json = getJSON()
        users = createUsers(from: json)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Check segue.identifier, left out for brevity.
        let destination = segue.destination as! YourDetailsViewController
        let cell = sender as! UITableViewCell
        let indexPath = tableView.indexPath(for: cell)!
        let user = users[indexPath.row]
        destination.user = user
    }

    // ... other funcs for table view ...

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let user = users[indexPath.row]
        // dequeue cell, set up with info from user, return it
    }
}
</code>```

Body:
The way I usually do this is to first map the JSON to model objects and use those model objects in the table data source to populate the table view. When a cell is tapped, I do the reverse mapping (from cell to model object) and can forward the model object (or a subset of the model object's information) to the next view controller in prepare(for:sender:). To make this happen, I set up the cell in Interface Builder to trigger a segue to the details view controller on selection.

Example code:

struct User
{
    let id: String
    let name: String
    // etc.
}

class YourTableViewController: UITableViewController
{
    var users: [User] = []

    override func viewDidLoad() {
        super.viewDidLoad()
        let json = getJSON()
        users = createUsers(from: json)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Check segue.identifier, left out for brevity.
        let destination = segue.destination as! YourDetailsViewController
        let cell = sender as! UITableViewCell
        let indexPath = tableView.indexPath(for: cell)!
        let user = users[indexPath.row]
        destination.user = user
    }

    // ... other funcs for table view ...

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let user = users[indexPath.row]
        // dequeue cell, set up with info from user, return it
    }
}


答:
The new constant is only defined within the scope of your if let, so as soon as the scope is over, your tempX is gone. That also means that you can reuse names within the if let scope.</p>

```<code>if let X = X {

}
</code>```

Title: Swift optional binding constant names

Body:
The new constant is only defined within the scope of your if let, so as soon as the scope is over, your tempX is gone. That also means that you can reuse names within the if let scope.

if let X = X {

}


问:
Missing assembly reference in Razor view
I have a MVC application which works fine when returning JSON for my API controllers. I've added a controller which should return a razor view, however I'm getting the following error when trying to load the page:

One or more compilation references are missing. Possible causes
include a missing 'preserveCompilationContext' property under
'buildOptions' in the application's project.json.

The type or namespace name 'DevTestViewModel' does not exist in the namespace 'MyApp.Api.Models' (are you missing an assembly
reference?)

I've simplified my view to:

```<code>@model List<MyApp.Api.Models.DevTestViewModel>

<h1>Hello World</h1>
</code>```

My model class is:

```<code>namespace MyApp.Api.Models {
    public class DevTestViewModel {

        public int Id { get; set; }

        public string Name { get; set; }

    }
}
</code>```

I've tried adding a _ViewImports.cshtml:

```<code>@using MyApp.Api
</code>```

I've also followed the suggestion in the error and set preserveCompilationContext in my project.json but it's made no difference:

```<code>"buildOptions": {
  "emitEntryPoint": true,
  "preserveCompilationContext": true
},
</code>```

It works fine when debugging locally. It's only once I publish to Azure that I'm have the problem. Not sure what I'm missing.

答: It looks like there was an issue with the deployment to Azure. Re-creating the Web App in Azure and then redeploying fixed the issue. </p>

Body:
I have a MVC application which works fine when returning JSON for my API controllers. I've added a controller which should return a razor view, however I'm getting the following error when trying to load the page:

One or more compilation references are missing. Possible causes
include a missing 'preserveCompilationContext' property under
'buildOptions' in the application's project.json.

The type or namespace name 'DevTestViewModel' does not exist in the namespace 'MyApp.Api.Models' (are you missing an assembly
reference?)

I've simplified my view to:

@model List<MyApp.Api.Models.DevTestViewModel>

Hello World

My model class is:

namespace MyApp.Api.Models {
    public class DevTestViewModel {

        public int Id { get; set; }

        public string Name { get; set; }

    }
}

I've tried adding a _ViewImports.cshtml:

@using MyApp.Api

I've also followed the suggestion in the error and set preserveCompilationContext in my project.json but it's made no difference:

"buildOptions": {
  "emitEntryPoint": true,
  "preserveCompilationContext": true
},

It works fine when debugging locally. It's only once I publish to Azure that I'm have the problem. Not sure what I'm missing.


答:
It's still wrong, it just happens to be working by (un)happy coincidence.

This code has undefined behaviour with all the usual caveats (it might always work, it might always work until it's too late to fix, it might set fire to your house and run away with your betrothed).

The compiler isn't required to issue a diagnostic (warning or error message) for every possible mistake, just because it isn't always possible to do so. Here, at least your current version of g++ hasn't warned. A different compiler, or a different version of g++, or even the same version with different flags, might warn you.

Title: Returning reference to local variable without trivial conversion