3 回答
TA贡献2041条经验 获得超4个赞
首先,您需要修复方法以返回适配器所需的数据,以将项目对象标识为
// return the new data from sourcein case of update
public Object getItem(int position) {
return grid[position];
}
// don't send 0 always
public long getItemId(int position) {
return position;
}
// invoke notifyDataSetChanged(); when there is a change in data source
public void update(int id, int player){
grid[id] = R.drawable.ic_notifications_black_24dp;
notifyDataSetChanged();
}
TA贡献1829条经验 获得超7个赞
您需要通知适配器数据元素已更改。试试这个update()方法:
public void update(int id, int player){
grid[id] = R.drawable.ic_notifications_black_24dp;
notifyDataSetChanged();
}
TA贡献1801条经验 获得超16个赞
好的,我发现了问题,我在 中设置了网格,getView(int position, View convertView, ViewGroup parent);
但它应该在构造函数中设置。问题是每次我点击一个项目时它都会重置网格中的值,所以该值没有改变。
添加回答
举报