2014-03-07 33 views
0

我有一个列表视图与每个元素中的图片和文本。如果用户点击该图像,并且如果用户再次单击该图像,则必须能够更改其中一个图像并将其更改回原始图像。我有一个基础适配器类,用于将数据添加到列表视图。在getview方法中,我设置了一个onclick监听器来改变它。我遇到的问题是,只有当我滚动元素并回到它时才会发生变化。我怎么改变,以便它将更新列表视图与滚动离开它。在listview中更新图片onclick

回答

0

您可以使用该方法

notifyDataSetChanged(); 

你在listViewAdapter(谁延伸BaseAdapter)改变图片src后

如。

public class ProductItemListView extends ListView { 

    public ProductItemListView() { 
     super(context); 
     mProductAdapter = new ProductItemAdapter(context); 
     this.setAdapter(mProductAdapter); 
    } 
} 



public class ProductItemAdapter extends BaseAdapter { 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ... 

     myImage.setBackgroundResource(R.drawable.other_image); 
     notifyDataSetChanged(); 

    } 
} 
+0

感谢它的工作 – Samantha