简体   繁体   中英

Strange glitch on ListView: text dissapears after pressing search action button

I've a ListView screen that is driving me mad.

Each row has three TextViews. The adapter is a custom ArrayAdapter that makes use of the view recycling mechanism: if the row is first requested, a new view is inflated, otherwise the recycled view is used. Everything works ok. I'm not showing it but for now assume it is correctly implemented.

This is how it looks normally:

在此处输入图片说明

There is a search button in the right upper corner of the screen. When clicked, every text view in the list is "cleared"! I've debugged the code and the textviews are there, the text is set and everything is ok except the text is barely or not shown. Here's a view dump taken with DDMS:

在此处输入图片说明

Looks like only the first letters of the text are shown. This only happens in certain devices, and only when the adapter's getView method returns the recycled view for the row, BUT only after pressing the search button, which makes the keyboard to show up (If i close it, the text is still missing). If I modify the getView method to always inflate every row this does not happen, but of course this is not an option since my list should be able to handle a large number of items.

Looks like a bug, but I need to do something about it.

I've also tested an alternative recycling mechanism based on a map (basically I put the view for each row in a map). Still the behavior is observed.

Device is a Samsung Galaxy SII running 4.1.2. Not happening in Galaxy SIII mini for instance.

Do you know what could be causing this glitch? Something related to the TextView's width?

Thanks in advance

I finally found the cause.

It was one of the TextViews in the adapter xml file. It was contained in a fixed-width LinearLayout. Its width was set to fill_parent , and changing it to wrap_content fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM