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

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

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
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 agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools