一直不明白listview中的复用,为什么会出现,项目多了。点击同一行的按钮,操作的不是指定行的对象。

仔细研读了代码,突然明白了。因为复用了,导致了position改变了。

伪码

if(convertview == null)

{

convertview = new xxview();

convertview.buttonone = find( R.id.xxx);

convertview.buttonone.onsetclick(...

(View v){

delete(position);

}

)

}

红字部分是错误的,因为这个position是view项目在看到的时候创造的,不是数据本身的。

所以我认为正确的,应该是

convertview.buttonone.onsetclick(...

(View v){

int mypostion = (int)v.getTag();

delete(mypostion);

}

 

在赋值的时候

 

.buttonone.setTag(postion)

 

相关文章:

  • 2021-04-13
  • 2021-12-05
  • 2021-07-11
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-21
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2021-07-27
相关资源
相似解决方案