我正在尝试在RecyclerView适配器中实现切换按钮(收藏夹)
当我单击ToggleButton时,它已成功收藏,然后再次单击了不喜欢的东西,但是问题是即使重新启动应用程序,我也如何在本地保存此状态。
这是我的模型班级:
stack_arrays = np.array([], dtype=np.float32)
dim_w, dim_h, rows = 0, 0, 0
sources = ["source_1", "source_2"]
for source in sources:
//return 3D array in the form of (N,W,H) where W and H are fixed but you dont know the size of W and H
new_arrays = get_arrays(source)
dim_w, dim_h = new_arrays.shape[1], new_arrays.shape[2]
rows = rows + new_arrays.shape[0]
stack_arrays = np.append(stack_arrays , new_arrays , axis=0)
new_arrays = new_arrays.reshape(rows, dim_w, dim_h)
这是我的切换按钮的OnClick()适配器代码:
int toggled = R.drawable.ic_star_red_24dp;
int untoglled = R.drawable.ic_star_border_black_24dp;
boolean isFavorite = false;
public int getToggled() {
return toggled;
}
public int getUntoglled() {
return untoglled;
}
public void setFavorite(boolean favorite) {
isFavorite = favorite;
}
public boolean isFavorite() {
return isFavorite;
}
也是这样:
holder.favorite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (newsModel.isFavorite)
newsModel.setFavorite(false);
else
newsModel.setFavorite(true);
notifyItemChanged(position);
}
});
现在,我该如何保存状态?