问题
so i have this listview, with the height of fillparent , and mainly it's taking half the size of the screen, but afterwards i need to change the parent layout of this listview. Here i start to notice that the app is freakeshly laging, after some diagnostic i understand that the getView() from the adapter is called so many times,
PS: i had this issue at fist when the listview height was at wrapcontent, changing it to fillparent solved the issue, but came again with the height change,
please if anyone has any clue about this, it would be much appreciated, thanks all
回答1:
If you think your app is lagging due to getView() method, you should try optimizing it. Android system keeps a pool of objects which you can reuse, those are given as a convertView parameter.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.rowlayout, null);
}
// asign correct values to your items - example:
TextView text = (TextView) convertView.findViewById(R.id.text);
text.setText(values.get(position));
//
return convertView;
}
回答2:
Thank you all guys, i got my mistake, when i try to change the height of its parent, i mistakly did RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
after changing it to FILL_PARENT, the problem went away thanks again for your time
来源:https://stackoverflow.com/questions/18923355/android-getview-called-multiple-times-after-listview-height-change