调整大小时 listView 行的冗余更新

发布于 2024-11-19 04:27:43 字数 724 浏览 4 评论 0原文

我在活动中使用 ListView 和自定义数组适配器(它只是覆盖 getView 方法)来进行某些聊天活动。当我打开软键盘列表视图调整大小(例如从 5 行变为 2 行可见行)时,但 getView 方法调用了 7 次:

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 view 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

如何防止这种开销?
谢谢帮助。

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 view 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

壹場煙雨 2024-11-26 04:27:43

AFAIK 这是 getView(); 的正常行为
您无法阻止对 getView() 的调用,但可以最大限度地减少进程开销。
你会使用类似的东西:

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文