Note that there are some explanatory texts on larger screens.

plurals
  1. POListView of WebViews - reusing items of different height fails; asks for all views before displaying any
    primarykey
    data
    text
    <p>I have an activity that displays a <code>ListView</code>. Each item in the <code>ListView</code> is a <code>LinearLayout</code> consisting of one <code>WebView</code>. There are potentially hundreds of items in the list and each is a different height.</p> <p>First problem is that when reusing a recycled view in <code>getView()</code>, the new view is always the height of the original view, even though I've set the <code>layout_height</code> for both the <code>LinearLayout</code> and the <code>WebView</code> to <code>wrap_content</code>.</p> <p>Second problem is that <code>getView()</code> seems to be getting called for every item in the list even though only the first five or six fit on the screen. I haven't seen this when using other list item types. For example, in another place I a list of custom views that are all the same height and I only see <code>getView()</code> being called for the number of views that initially fit on the screen.</p> <p>So... I need to figure out how to force recycled <code>WebViews</code> to render their new contents so their height can be calculated instead of just using the previous height. And I'd like to know why the system is asking me for ALL my items in this case.</p> <p>Here's the requisite code snippets:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;ListView android:id="@+id/topPane" android:layout_width="fill_parent" android:layout_height="fill_parent" android:dividerHeight="1.0px" android:divider="#FFFFFF" android:smoothScrollbar="false" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Rows are built from:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" &gt; &lt;WebView android:id="@+id/rowWebView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="0.0px" android:scrollbars="none" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is getView() in my adapter. HTML snippets come from an array of Strings for now. </p> <pre><code> @Override public View getView(int position, View convertView, ViewGroup parent) { String item = (String) getItem(position); if (convertView == null) { convertView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.rowview, parent, false); } WebView wv = (WebView) convertView.findViewById(R.id.rowWebView); wv.loadDataWithBaseURL(null, item, "text/html", "utf-8", "about:blank"); return convertView; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload