RecyclerView notifyItemChanged(position)未更新该行的位置

时间:2015-08-24 09:36:25

标签: android android-recyclerview

数据模型

public class Model implements Serializable {
@SerializedName("shortlisted_state") @Expose private boolean shortlistState;

public void setShortlistState(boolean shortlistState) {
  this.shortlistState = shortlistState;
}

public boolean getShortlistState() {
  return shortlistState;
}
}

在项目点击recyclerview上,用这种方式转到另一个带有startActivityForResult的活动。

@Override public void onItemClick(View view, int position) {
Intent i = new Intent(getActivity(), ListingDetailActivity.class);
i.putExtra(ListingDetailActivity.KEY_LISTING, (Serializable) adapter.getListings());
i.putExtra(ListingDetailActivity.POSITION, position);
startActivityForResult(i, ACTION_DETAIL);
}

然后在用户进行更改并返回列表活动后

@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ACTION_DETAIL && resultCode == Activity.RESULT_OK) {
  final ArrayList<Integer> positions = data.getIntegerArrayListExtra("position");
  final boolean[] states = data.getBooleanArrayExtra(ListingDetailActivity.KEY_LISTING);
  for (int i = 0; i < positions.size(); i++) {
    adapter.updateChanges(positions.get(i), states[i]);
  }
 }
}

在RecyclerView适配器中,我就是这样的notifyItemChange,

public void updateChanges(int position, boolean status) {
listings.get(position).setShortlistState(status);
notifyItemChanged(position);
}

listing是来自上面的模型clas的ArrayList列表。

但RecyclerView没有更新该行。有什么我想念的吗?

0 个答案:

没有答案