我正在尝试创建ArrayList
个观看次数。不幸的是,ArrayList
值会随着视图引用更改而更改。
我有两个引用,一个在偶数位置添加,另一个在奇数位置添加。我看到当第3项出现时的行为,第1项的值也发生变化,同样也适用于偶数。
我需要在某些基础上更新视图列表。怎么解决这个问题?我试过这样的事情,但没有奏效:
private void addItemAt(int depth,View retView){
ArrayList<View> viewsAdded = new ArrayList<View>(viewsAtDepths.size());
for (int i = 0; i < viewsAtDepths.size(); i++) {
View v = viewsAtDepths.get(i);
viewsAdded.add(v);
}
viewsAtDepths = viewsAdded;
if(depth < viewsAtDepths.size()){
Log.d(TAG,"Replacement at depth "+depth);
viewsAtDepths.set(depth, retView);
}
else{
Log.d(TAG,"Added at depth "+depth);
viewsAtDepths.add(retView);
}
Log.d(TAG,"ADD item is made "+depth +" and total nu of items are "+viewsAtDepths.size());
for (int i = 0; i < viewsAtDepths.size(); i++) {
if(viewsAtDepths.get(i) instanceof ListView){
ListView lv = (ListView) viewsAtDepths.get(i);
if(lv.getItemAtPosition(i) instanceof Node){
Node n = (Node) lv.getItemAtPosition(0);
Log.d(TAG,"Title Name at "+i+" selected node is "+n.title);
}
else{
if(lv.getItemAtPosition(i) instanceof String){
Log.d(TAG,"String Title Name at "+i+" selected node is "+lv.getItemAtPosition(i));
}
}
}
}
}