0

这是我的代码: 这里 _alProduct 是在主类中静态定义的 ArrayList。我在长按列表视图时从 _alProduct 中删除一个项目。现在我想显示删除了已删除项目的列表视图。

公共类 MCRActivity2 扩展 Activity {

TextView tvShoppingCart;
ListView lvSelectedItems;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mcractivity2);

    lvSelectedItems = (ListView) findViewById(R.id.lvSelectedItems);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, MobileCashRegisterActivity._alProduct);

    lvSelectedItems.setAdapter(adapter);

    lvSelectedItems.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> adapter, View view,
                int position, long arg3) {
            // TODO Auto-generated method stub  
            String text = "Clicked item is " + adapter.getItemAtPosition(position);

            Toast.makeText(getApplicationContext(),text,Toast.LENGTH_LONG).show();//    ""+ lvSelectedItems.getSelectedItem().toString(),Toast.LENGTH_LONG).show();

            MobileCashRegisterActivity._alProduct.remove(position);
            MobileCashRegisterActivity._alPrice.remove(position);
            MobileCashRegisterActivity._alQuantity.remove(position);

            return false;
        }
    });
    }
}
4

1 回答 1

3

调用remove()你的,ArrayAdapter而不是调用remove(). ArrayList这将从中删除项目ArrayList并告诉AdapterView刷新其内容。

于 2012-07-19T17:15:56.663 回答