0

この水平リスト ビューを使用していますが、notify 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();

..

ImageAdapter クラス

            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 クラス内のアイテムを削除するための buttonlistener がある場合、リストからアイテムを削除して適切に更新します

4

1 に答える 1

0
imageAdapter = new ImageAdapter(this, results);
listView.setAdapter(new ImageAdapter(this, results));

2 つの異なる を作成していますImageAdapter。呼び出しても相手には影響notifyDataSetChanged()imageAdapterませんImageAdapter

私はあなたがこれをするつもりだったと思います:

imageAdapter = new ImageAdapter(this, results);
listView.setAdapter(imageAdapter);
于 2013-07-19T01:57:14.207 に答える