0
这是我的代码: 这里_alProduct是一个在主类中定义的静态的ArrayList。 我正在从_alProduct上长按一下listview就删除一个项目。 现在我想显示删除删除项目的列表视图。我如何刷新android中的listview?
公共类MCRActivity2您ArrayAdapter
延伸,而不是在ArrayList
调用remove()
活动{
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;
}
});
}
}
可以请你写一些代码先生,怎么做,因为它显示的功能像removeAllViews()等 – 2012-07-19 17:20:24
我找不到apapter.remove()函数 – 2012-07-19 17:29:32
@ user1507602:这是'ArrayAdapter'的链接' remove()':http://goo.gl/C5qMg – CommonsWare 2012-07-19 17:34:39