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

用户名

我所拥有的是带有自定义适配器的列表视图,它从意图有效的数组中获取数据,这很好..我添加的是一个按钮,当我单击它时我想清除列表..但是没有清除列表..为什么会这样?

这是我的清单代码:

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

谁能帮我?

阿波罗夫

请在SetAdapterList()中进行注释onClick因为它正在重新填充ArrayList您传递给的CustomAdapter

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Hashmap为自定义列表视图创建自定义适配器

列表视图的自定义适配器

自定义适配器不显示列表视图

将列表视图的数据从Asynctask传递到自定义列表适配器类

使用自定义适配器视图时,如何使列表视图可点击?

使用自定义适配器和视图持有器的Android列表视图

在自定义列表视图适配器中使用多个视图

当我在自定义适配器中使用imagebutton时,setOnItemClickListener在列表视图中不起作用

在自定义可扩展列表适配器中无法充实视图

无法解析适配器中自定义列表视图的布局

如何使用自定义适配器单击列表视图中的项目

使用带有文本和图像的自定义适配器在列表视图中搜索

对于使用一个自定义适配器的多个列表视图

使用自定义列表视图适配器和不同布局的结果不正确

使用外部XML文件进行自定义列表视图适配器?

使用自定义适配器的Android数据绑定

Android:在我的自定义适配器中使用数据绑定时未分配值

我如何按字母顺序对listView的文件进行排序并集成列表适配器?我正在使用自定义适配器

如何从自定义列表视图适配器获取数据并传递给意图添加额外的内容?

自定义文本视图适配器不适用于列表视图

列表视图中的页脚按钮,如何从自定义列表适配器获取价值

使用适用于Android应用的自定义适配器将项目动态添加到列表视图

使用自定义适配器在列表视图中选择/突出显示多个项目-Android

自定义视图的适配器中的NullPointerException

自定义适配器视图(带有图片)

无法在滑动视图中将自定义listView和适配器与listFragment一起使用

自定义列表视图和适配器覆盖getView,更改文本颜色

如何创建自定义适配器以将 cardview 用于片段内的列表视图

自定义适配器不在列表视图中显示文本