我正在使用这个水平列表视图,但是当我调用通知 notifyDataSetChanged() Mainactivity 类时它不会刷新视图
oncreate{
products = new ArrayList<Product>();
listView = (HorizontalListView) findViewById(R.id.listView1);
imageAdapter = new ImageAdapter(this, products);
listView.setAdapter(new ImageAdapter(this, products));
...
private void loadProduct(Intent data) {
Bundle extras = data.getExtras();
Product p = (Product)extras.getParcelable(PASSED_PRODUCT);
//tried using imageAdapter.add(p) aswell but doesnt work either
products.add(p);
imageAdapter.notifyDataSetChanged();
..
图像适配器类
public void add(Product p) {
products.add(p);
// notify the list that the underlying model has changed
notifyDataSetChanged();
}
public void remove(int position) {
products.remove(position);
notifyDataSetChanged();
}
如果我有一个按钮监听器来删除 imageadapter 类中的项目,它可以很好地从列表中删除项目并正确刷新