您看起来只需要在膨胀的视图上运行findViewById,否则它只会找到第一个只是循环中的第一个:
View child = getLayoutInflater().inflate(R.layout.cellevery, lLfD);
ImageView avatar = (ImageView)child.findViewById(R.id.cellAvatar);
downloadFile(userPicture, avatar);
TextView cellName = (TextView)child.findViewById(R.id.cellName);
cellName.setText(userName);
以下是循环中findViewById的解释:
Loop 1:
1LfD->child1->R.id.cellAvatar (findViewById(R.id.cellAvatar) finds this one)
Loop 2:
1Lfd->
child1->R.id.cellAvatar
child2->R.id.cellAvatar (findViewById(R.id.cellAvatar) finds the child1.cellAvatar again)
Loop 3:
1LfD->
child1->R.id.cellAvatar
child2->R.id.cellAvatar
child3->R.id.cellAvatar (findViewById(R.id.cellAvatar) finds the child1.cellAvatar again)
通过使用child.findViewById(R.id.cellAvatar),它确保为每次循环运行找到正确的R.id.cellAvatar.
那有意义吗?
更新2:
你打电话的时候:
getLayoutInflater().inflate(R.layout.cellevery, lLfD);
您已将父视图设置为第二个参数,因此您无需调用:
lLfD.addView(child);