title: how can i add items to an list view with custom adapter each time i click on the button?
body: <p>what i am trying to do is something look like add to cart thing but on my android app , first of all i have <strong>add to cart activity</strong> which has all the values i need when i press the button i send my data as put extra to <strong>cartList</strong> Activity and it display on row and each time i press the button on some item it clear the array and display only one row ! but what i really need to do is when each time i press the button i want it to add on the previous items and display them all .. here is my add to cart activity :</p>
  
  <pre><code>public class AddToCart extends Activity{
  
      EditText quantity=null;
      TextView total=null;
      TextView name=null;
      TextView price=null;
      TextView ava=null;
      double totalprice=0.0;
  
      ArrayList&lt;String&gt; listOfItemNames = new ArrayList&lt;String&gt;();
      List&lt;listClass&gt;testList;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.info);
          Intent test = getIntent();
  
  
  
          Intent intent = getIntent();
          final String itemprice = intent.getStringExtra("price");
          final String itemname = intent.getStringExtra("item");
          final String itemava = intent.getStringExtra("ava");
          final int imagehandler=intent.getIntExtra("image", 0);
          Log.e("image handler",imagehandler+"");
           name=(TextView)findViewById(R.id.textView2);
           price=(TextView)findViewById(R.id.textView4);
           total=(TextView)findViewById(R.id.textView7);
           ava=(TextView)findViewById(R.id.textView9);
          quantity=(EditText)findViewById(R.id.editText1);
          Button addtocart=(Button)findViewById(R.id.button1);
          ImageView imageview=(ImageView)findViewById(R.id.imageView1);
  
          name.setText(itemname);
          price.setText(itemprice);
          ava.setText(itemava);
          imageview.setImageResource(imagehandler);
  
  
  
              addtocart.setOnClickListener(new OnClickListener() {
  
  
                  @Override
                  public void onClick(View v) {
                      final String quantityvalue=quantity.getText().toString();
                      CharSequence currentavaiable=ava.getText();
                      int currentava=Integer.parseInt((String) currentavaiable);
                      Editable checked = quantity.getText();
                      String checkquantity=checked.toString();
                      Log.e("checked ",checked+"");
                      Log.e("check quantity",checkquantity);
                      try{
  
                  if(checkquantity==null){
                      Toast.makeText(AddToCart.this,"please enter quantity for your item", Toast.LENGTH_LONG).show();
                  }
  
                  else{
                      int x=0;
                      double y=0.0;
  //                  String xvalue=quantity.getText().toString();
                       x = Integer.parseInt(quantityvalue);
                       Log.e("x",x+"");
                       y = Double.parseDouble(itemprice);
                      Log.e("x",x+"");
                      Log.e("y",y+"");
                       totalprice=x*y;
                      total.setText(totalprice+"");
                      Toast.makeText(AddToCart.this,"your item added succesfully !", Toast.LENGTH_LONG).show();
  
                  }
  
                  Intent newintent=new Intent(AddToCart.this,CartList.class);
                  newintent.putExtra("itemname",itemname);
                  newintent.putExtra("itemprice",itemprice);
                  newintent.putExtra("itemquantity",quantityvalue);
                  newintent.putExtra("totalprice",totalprice);
                  newintent.putExtra("image", imagehandler);
  
                  startActivity(newintent);
                  }//view
                      catch(Exception e){
                          e.printStackTrace();
                      }
                  }
              });
      }
  }
  </code></pre>
  
  <p>and here is cart list class :</p>
  
  <pre><code>public class CartList extends Activity {  
      ListView list;
  
      List&lt;CartItems&gt; detailsList = new ArrayList&lt;CartItems&gt;();
      ArrayList&lt;String&gt; listtest=new ArrayList &lt;String&gt;();
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.cart_list);
  
  
  
  
  
          initializeComponents();
  
          detailsList = SetAdapterList();
  
          CustomAdapter adapter=new CustomAdapter(this,detailsList);
  
          list.setAdapter(adapter);
  
  
  
  
      }
  
  
      private void initializeComponents()
      {
          list=(ListView)findViewById(R.id.listView1);
      }
  
  
  
  
  
  
  
      private List&lt;CartItems&gt; SetAdapterList() 
      {
          // TODO Auto-generated method stub
  
          CartItems details;
  
           List&lt;CartItems&gt; detailsList = new ArrayList&lt;CartItems&gt;();
  
           try{
           Intent newintent = getIntent();
           final String itemname = newintent.getStringExtra("itemname");
          final String itemprice = newintent.getStringExtra("itemprice");
          final String itemquantity = newintent.getStringExtra("itemquantity");
          final double totalprice = newintent.getDoubleExtra("totalprice", 0.0);
          String totprice=String.valueOf(totalprice);
  //      ArrayList &lt;String&gt; itemnames=new ArrayList&lt;String&gt;();
           listtest.add(itemname);
           Log.e("listtest",listtest+"");
          final int imagehandler=newintent.getIntExtra("image", 0);
          Log.e("image handler",imagehandler+"");
          for(int i = 0; i&lt; listtest.size(); i++)
          {
          details = new CartItems(itemname,itemprice,itemquantity,totprice,imagehandler);
          detailsList.add(details);
          }
  
  
           }
           catch(Exception e){
               e.printStackTrace();
           }      
              return detailsList;
      }   
  
  }
  </code></pre>
  
  <p>and here is my custom adapter :</p>
  
  <pre><code>public class CustomAdapter extends ArrayAdapter&lt;CartItems&gt; {
  
      Context context;
      List&lt;CartItems&gt;Clist = new ArrayList&lt;CartItems&gt;();
  
      public CustomAdapter(Context context, List&lt;CartItems&gt; detailsList) {
          super(context, R.layout.single_row, R.id.textView1, detailsList);
          // TODO Auto-generated constructor stub
  
          this.context=context;
          this.Clist = detailsList;
  
  
      }
  
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View row=inflater.inflate(R.layout.single_row, parent,false);
          ImageView myimage=(ImageView) row.findViewById(R.id.imageView1);
          TextView items=(TextView)row.findViewById(R.id.textView1);
          TextView totalprice=(TextView)row.findViewById(R.id.textView2);
  
  
  
          items.setText(Clist.get(position).getItemName());
          totalprice.setText(Clist.get(position).getTotalPrice());
          myimage.setImageResource(Clist.get(position).getImage());
  
          return row;
      }
  
  }
  </code></pre>
  
  <p>here is my itemcart class :</p>
  
  <pre><code>public class CartItems {
  
      private String itemName;
      private String itemPrice;
      private String Quantity;
      private String totalPrice;
      private int image;
  
      public CartItems(String itemname,String itemprice, String quantity, String totalprice2, int image){
          this.itemName=itemname;
          this.itemPrice=itemprice;
          this.Quantity=quantity;
          this.totalPrice=totalprice2;
          this.image=image;
      }
  //getter and setters 
  }
  </code></pre>
  
  <p>please can anyone help me?? i am so despaired !!</p>