Android 我能做的';是否无法使用自定义适配器数据清除我的列表视图?

Android 我能做的';是否无法使用自定义适配器数据清除我的列表视图?,android,android-listview,custom-adapter,Android,Android Listview,Custom Adapter,我拥有的是一个带有自定义适配器的列表视图,它从一个数组中获取数据,该数组是从一个可以正常工作的意图中获取的。。我添加的是一个按钮,我想在单击它时清除我的列表。。但这并没有清除清单。。为什么会发生这种情况 以下是我的列表代码: public class CartList extends Activity { ArrayList <String> listmix=new ArrayList<String>(); ListView list; Ca

我拥有的是一个带有自定义适配器的列表视图,它从一个数组中获取数据,该数组是从一个可以正常工作的意图中获取的。。我添加的是一个按钮,我想在单击它时清除我的列表。。但这并没有清除清单。。为什么会发生这种情况

以下是我的列表代码:

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);
    }     
}
public类CartList扩展活动{
ArrayList listmix=新的ArrayList();
列表视图列表;
新测试;
静态列表详细信息列表=新的ArrayList();
双重totalpricetext=0.0;
TextView totalpricevalue;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE\u NO\u TITLE);
setContentView(R.layout.cart_列表);
totalpricevalue=(TextView)findViewById(R.id.totalpricevalue);
按钮清除=(按钮)findViewById(R.id.button1);
clear.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
detailsList.clear();
SetAdapterList();
CustomAdapter=新的CustomAdapter(CartList.this,detailsList);
list.setAdapter(适配器);
}
});
初始化组件();
AlertDialog.Builder alertDialogBuilder=新建AlertDialog.Builder(CartList.this);
alertDialogBuilder.setTitle(“轻松购物”);
alertDialogBuilder
.setMessage(“您想继续购物吗?”)
.setCancelable(错误)
.setPositiveButton(“是”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
//意向意向=新意向(CartList.this,EasyShopping.class);
//                      
//星触觉(意向);
dialog.cancel();
}
})
.setNegativeButton(“否”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
启动意图();
//getlist();
}
});
AlertDialog AlertDialog=alertDialogBuilder.create();
alertDialog.show();
}
私有void initializeComponents()
{
列表=(ListView)findViewById(R.id.listView1);
}
私有void SetAdapterList()
{
//TODO自动生成的方法存根
项目详情;
//List detailsList=new ArrayList();
试一试{
Intent newintent=getIntent();
最终字符串itemname=newintent.getStringExtra(“itemname”);
最终字符串itemprice=newintent.getStringExtra(“itemprice”);
最终字符串itemquantity=newintent.getStringExtra(“itemquantity”);
最终双倍总价=newintent.getDoubleExtra(“总价”,0.0);
String totprice=String.valueOf(totalprice);
final int-imagehandler=newintent.getIntExtra(“图像”,0);
Log.e(“图像处理程序”,imagehandler+”);
详细信息=新CartItems(itemname、itemprice、itemquantity、totprice、imagehandler);
详细信息列表。添加(详细信息);
}
捕获(例外e){
e、 printStackTrace();
}
Log.e(“detailsList”,detailsList+”);
getdata();
}
私有void getdata(){
//TODO自动生成的方法存根
CartItems项目;
对于(int i=0;i

有人能帮我吗?

onClick
中注释
SetAdapterList()
,因为它正在重新填充传递给
CustomAdapter的
ArrayList
中的
ArrayList
,您似乎正在
SetAdapterList()中填充
ArrayList
。你为什么要点击按钮呢?我知道这是错误的,但我尽了一切努力使它正确。。那么你能告诉我问题是什么吗?试着在
onClick
中对方法
SetAdapterList()
进行注释,它起作用了。请将您的注释作为答案,以便我批准它