我正在ListView
工作,点击项目时我需要将图片更改为列表中的项目视图作为我的照片。但是当我在列表中向下滚动时,我发现其他项目被点击了。这是我的代码
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i != lastpostion) {
viewselected = getViewByPosition(lastpostion, listView);
play = viewselected.findViewById(R.id.play);
pause = viewselected.findViewById(R.id.pause);
play.setVisibility(View.GONE);
pause.setVisibility(View.VISIBLE);
}
isfound = true;
play = view.findViewById(R.id.play);
pause = view.findViewById(R.id.pause);
play.setVisibility(View.VISIBLE);
pause.setVisibility(View.GONE);
//Toast.makeText(this,""+listView.getFirstVisiblePosition(),Toast.LENGTH_SHORT).show();
//Toast.makeText(this,""+listView.getChildCount(),Toast.LENGTH_SHORT).show();
lastpostion = i;
}
答案 0 :(得分:0)
我认为这样可以改变您的代码
public int climbStairs(int n) {
int dp[] = new int[n+1];
if(n==1) {
return 1;
} else if(n==2){
return 2;
} else {
dp[1] = 1;
dp[2] = 2;
for(int i =3; i<=n;i++) {
dp[i] = dp[i-1] + dp[i-2];
}
return dp[n];
}
}