Home Java javaTutorial Solution to the problem of repeatedly executing getView when ListView is refreshed multiple times in Android

Solution to the problem of repeatedly executing getView when ListView is refreshed multiple times in Android

Jan 20, 2017 pm 03:30 PM

I didn’t notice that listview’s getView would be executed multiple times before. This time because the layout was more complicated, I went to breakpoint tracking during testing and found that the same piece of data was being executed repeatedly. I thought it was strange, so I searched online. The explanations on the Internet are basically the same, that is, when the ListView is laid out, neither height nor width is fill_parent, resulting in continuous calculation of height and continuous refreshing. Or its parent container is not set to fill_parent.

If the layout is too complex, it is unrealistic to adjust everything according to fill_parent. So I thought of another solution, which is to dynamically fix the height.
After the program runs, fix the height of the ListView and then initialize the Item information.

private void fixedListView(){ 
listView = (ListView) findViewById(R.id.listview); 
ViewGroup.LayoutParams params = listView.getLayoutParams(); 
layout = (HorizontalScrollView) findViewById(R.id.layout); 
params.height = layout.getHeight(); //需要设置的listview的高度,你可以设置成一个定值,也可以设置成其他容器的高度,如果是其他容器高度,那么不要在oncreate中执行,需要做延时处理,否则高度为0 
listView.setLayoutParams(params); 
}
Copy after login

It is found that the refresh speed of ListView is greatly accelerated. Colleagues also solved the problem that if there is a listener for addTextChangedListener(new TextWatcher() in the text input EditText in Item, the listening code will be executed multiple times.

More solutions to the problem of repeatedly refreshing ListView in android and repeatedly executing getView For related articles, please pay attention to PHP Chinese website

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)