【发布时间】:2017-04-26 04:53:19
【问题描述】:
几天来,我一直在尝试在共享首选项中保存一个整数数组列表,但不知道该怎么做。
这是我要保存的数组列表
////list that contains checked routes///
ArrayList<Integer> checkedRoutePosition = new ArrayList<>();
这是数组如何获取其中的值
int listViewItemPosition = ((Activity) getContext()).getIntent().getIntExtra("listViewItemPosition",0);
checkedRoutePosition.add(listViewItemPosition);
在您单击后退按钮后的另一个活动中,会启动一个新意图,将我带到此活动。 Intent 传入了我需要保存到数组的 listViewItemPosition 值。
以上代码行在我的列表视图自定义适配器的 getView 方法中。保存它们后,我想将它们与我的 getView 中的位置进行比较。在值相等的地方,我想设置某个图像。这段代码是正确的方法吗?
for(int i=0; i<checkedRoutePosition.size(); i++)
if(position == checkedRoutePosition.get(i)) {
checkImageView.setImageResource(checkImageResourceId);
}
感谢您的帮助!
【问题讨论】:
标签: android arrays listview sharedpreferences