When I scroll a listview with a custom adapter too fast up and down, getView() starts behaving oddly. Why?

左心房为你撑大大i 提交于 2019-12-04 08:22:16

Android reuses views fairly aggressively, and it is quite possible that a view that was used as an email address row gets reused on a row that's supposed to display a label, and vice-versa.

As a result, you cannot rely on "default" values. Set your padding, typeface, text size and background color in all cases:

if (item.equals("Name") || item.equals("Mobile") || item.equals("Home") || item.equals("Email") || item.equals("Address")) {
    text.setBackgroundColor(0xFF575757);
    text.setTextSize(15);
    text.setTypeface(null, Typeface.BOLD);
    text.setPadding(8, 5, 0, 5);
} else {
    text.setBackgroundColor(DEFAULT_BACKGROUND);
    text.setTextSize(DEFAULT_TEXT_SIZE);
    text.setTypeface(null, DEFAULT_TYPEFACE);
    text.setPadding(15, 15, 0, 15);
}
cErEbRaL aSsAsSiN

Don't need to do anything. I too faced the same problem and solved it like this:

Just inside the getView method add a first line

convertView=null; 

It wont redraw the view immediately destroyed but instead would create new ones each time based on your logic (even odd or whatever)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!