开发者

Redundand updating of listView rows on resize

I'm use ListView in my activity with custom array adapter (it just overrides getView method) for some chat activity. When i open soft keyboard listview resizing (for example from 5 to 2 visible rows), but getView method called 7 times:

07-11 11:59:13.185: DEBUG/*: [ChatMessageArrayAdapter] generating view for pos:5
07-11 11:59:13.346: DEBUG/*: [ChatMessageArrayAdapter] generating view for pos:4
07-11 11:59:13.485: DEBUG/*: [ChatMessageArrayAdapter] generating vi开发者_Go百科ew for pos:3
07-11 11:59:13.625: DEBUG/*: [ChatMessageArrayAdapter] generating view for pos:2
07-11 11:59:13.775: DEBUG/*: [ChatMessageArrayAdapter] generating view for pos:1
07-11 11:59:14.015: DEBUG/*: [ChatMessageArrayAdapter] generating view for pos:5
07-11 11:59:14.135: DEBUG/*: [ChatMessageArrayAdapter] generating view for pos:4

How do i can prevent this overhead?

thx for help.


AFAIK This is normal Behavior of the getView(); You cannot prevent the call to the getView() but can minimize the process overhead. You would use something like:

public View getView(final int position, View convertView, ViewGroup parent) {
    View row = null;
    if(convertView == null)
    {
        row = LayoutInflater.from(mContext).inflate(R.layout.row, null);
        //initialize and set values of components inside row for the first time.
    }
    else
    {
        row = convertView;
    }
    return row;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜