简体   繁体   English

我无法使用自定义适配器数据清除列表视图?

[英]what i can't clear my list view with custom adapter data?

what i have is a list view with custom adapter and it get data from an array that been taking from an intent which works fine .. what i have added is a button and i want to clear my list when i click it .. but it doesn't clear the list .. why this is happening?? 我所拥有的是带有自定义适配器的列表视图,它从意图有效的意图中获取数组数据。.我添加的是一个按钮,当我单击它时我想清除列表..但是没有清除列表..为什么会这样?

here my list code : 这是我的清单代码:

public class CartList extends Activity {


     ArrayList <String> listmix=new ArrayList<String>();
    ListView list;
    CartItems newtest;
    static List<CartItems> detailsList = new ArrayList<CartItems>();
    double totalpricetext=0.0;
    TextView totalpricevalue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.cart_list);
        totalpricevalue=(TextView)findViewById(R.id.totalpricevalue);
        Button clear=(Button)findViewById(R.id.button1);
        clear.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                detailsList.clear();
                  SetAdapterList();


                    CustomAdapter adapter=new CustomAdapter(CartList.this,detailsList);

                    list.setAdapter(adapter);
            }
        });
        initializeComponents();

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CartList.this);


            alertDialogBuilder.setTitle("easy shopping");
            alertDialogBuilder
                .setMessage("Do you like to Continue shopping?")
                .setCancelable(false)
                .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
//                       Intent intent=new Intent(CartList.this,EasyShopping.class);
//                      
//                      startActivity(intent);
                        dialog.cancel();


                    }
                  })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {

                         launchIntent();
                          // getlist();
                    }


                });

                AlertDialog alertDialog = alertDialogBuilder.create();          
                alertDialog.show();

    }

    private void initializeComponents()
    {
        list=(ListView)findViewById(R.id.listView1);
    }



    private void SetAdapterList() 
    {
        // TODO Auto-generated method stub

        CartItems details;
         //List<CartItems> detailsList = new ArrayList<CartItems>();

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

        final int imagehandler=newintent.getIntExtra("image", 0);
        Log.e("image handler",imagehandler+"");
        details = new CartItems(itemname,itemprice,itemquantity,totprice,imagehandler);
        detailsList.add(details);


         }
         catch(Exception e){
             e.printStackTrace();
         }
         Log.e("detailsList",detailsList+"");
            getdata();
    }



  private void getdata() {
        // TODO Auto-generated method stub
      CartItems item;

      for(int i = 0; i < detailsList.size();i++){
      item = detailsList.get(i);
      String itemname=item.getItemName();
      listmix.add(itemname);
      String itemprice=item.getItemPrice();
      listmix.add(itemprice);
      String itemQuantity=item.getQuantity();
      listmix.add(itemQuantity);
      String itemtotalPrice=item.getTotalPrice();
      listmix.add(itemtotalPrice);
      Log.i("myLog","then name of item is "+item.getItemName()+"");
      Log.i("listmix",listmix+"");
      double doubleprice = Double.parseDouble(itemtotalPrice);
        totalpricetext=totalpricetext+doubleprice;
        totalpricevalue.setText("the total amount of your cart is "+totalpricetext+" JD");
      }
    }

@Override
protected void onResume() {
      SetAdapterList();


    CustomAdapter adapter=new CustomAdapter(this,detailsList);

    list.setAdapter(adapter);

    super.onResume();
}  



private void launchIntent() {
        // TODO Auto-generated method stub
      Intent intent=new Intent(this,PersonalInfo.class);
      intent.putStringArrayListExtra("listmix", listmix);
        startActivity(intent);
    }     
}

can anyone help me? 谁能帮我?

onClick注释SetAdapterList() ,因为它正在重新填充要传递给CustomAdapterArrayList

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM