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