Note that there are some explanatory texts on larger screens.

plurals
  1. POListView ghosting when using DrawerLayout with Fragments
    text
    copied!<p>My layout was working fine before I switched it to use fragments inside the DrawerLayout. After that the ListView in the main view ghosts a copy of the list when scrolling.</p> <p>The ListView contents scroll, but a copy of the first page remains on screen. I've been logging debug messages and there is no second copy of listview created, and no second copy of data sent from the adapter.</p> <p><img src="https://i.stack.imgur.com/V9gL2.png" alt="enter image description here"></p> <p>The layout for the activity uses DrawerLayout with fragments before switching to fragments it worked fine.</p> <pre><code>&lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="400dp" android:layout_height="800dp"&gt; &lt;!-- The main content view --&gt; &lt;fragment android:name="com.nosweatbudgets.receipts.ReceiptsFragment" android:id="@+id/receipts_fragment" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;!-- The navigation drawer --&gt; &lt;fragment android:name="com.nosweatbudgets.navigate.NavigateFragment" android:id="@+id/navigate_fragment" android:layout_width="300dp" android:layout_height="match_parent" android:layout_gravity="start" /&gt; &lt;/android.support.v4.widget.DrawerLayout&gt; </code></pre> <p>The fragment classes are each very simple.</p> <p>ReceiptsFragment's onCreateView looks like this.</p> <pre><code> View view = inflater.inflate(R.layout.receipts, container, false); _adapter = new ReceiptsAdapter(inflater); ListView list = (ListView) view.findViewById(R.id.receipt_list); list.setAdapter(_adapter); _adapter.Refresh(); return view; </code></pre> <p>NavigateFragment's onCreateView is basically the same with a different adapter. It's the ReceiptsFragment that is ghosting while the NavigateFragment does not ghost. Yet they can basically the same approach.</p> <pre><code> View view = inflater.inflate(R.layout.navigate, container, false); _navigate = new NavigateAdapter(inflater); // setup the list view for the side ListView list = (ListView) view.findViewById(R.id.left_drawer); list.setAdapter(_navigate); _navigate.Refresh(); return view; </code></pre> <p>For the above fragment classes I'm using the following layouts.</p> <p><code>receipts.xml</code> looks like this.</p> <pre><code>&lt;RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/receipt_list"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p><code>navigate.xml</code> looks like this.</p> <pre><code>&lt;RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;ListView android:id="@+id/left_drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:choiceMode="singleChoice" android:background="#EEEEEE"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The pull out navigate listview works just fine, but the main receipts listview has the ghosting problem.</p> <p>I'm completely stumped as to what is causing this.</p> <p><strong>EDIT</strong>:</p> <p>Here is how views are created in the <code>ReceiptsAdapter</code>.</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { view = _inflater.inflate(R.layout.receipt, null); } TextView txt_vendor = (TextView) view.findViewById(R.id.receipt_vendor); TextView txt_category = (TextView) view.findViewById(R.id.receipt_category); TextView category_btn = (TextView) view.findViewById(R.id.category_btn); Model receipt = _receipts.get(position); int vendor_id = receipt.getAsInteger("smart_vendor_id"); int category_id = receipt.getAsInteger("smart_category_id"); if (_vendors.indexOfKey(vendor_id) &gt;= 0) { txt_vendor.setText(_vendors.get(vendor_id)); } else { txt_vendor.setText("Select Vendor"); } if (_categories.indexOfKey(category_id) &gt;= 0) { String cat = _categories.get(category_id); txt_category.setText(cat); category_btn.setText(Category.ShortTitle(cat)); category_btn.setBackgroundColor(Category.Color(cat)); //txt_category.setBackgroundColor(c); } else { txt_category.setText("Select Category"); category_btn.setText("N/A"); } ((TextView) view.findViewById(R.id.receipt_amount)).setText("$" + receipt.getAsString("amount")); ((TextView) view.findViewById(R.id.receipt_payment)).setText(receipt.getAsString("payment")); ((TextView) view.findViewById(R.id.receipt_date)).setText(receipt.getAsString("receipt_date")); return view; } </code></pre> <p><strong>EDIT</strong>:</p> <p>This is how the Activity for the layout attaches the fragments via the <code>onCreate</code> method.</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // the layout uses fixed width/size, because the layout editor won't render match_parent. // so I replace the layout parameters here with match_parent. DrawerLayout layout = (DrawerLayout) getLayoutInflater().inflate(R.layout.main, null); DrawerLayout.LayoutParams param = new DrawerLayout.LayoutParams(ViewGroup.LayoutParams .MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layout.setLayoutParams(param); setContentView(layout); // configure this activity StyleActionBar(); // Add the fragments getSupportFragmentManager().beginTransaction() .add(R.id.navigate_fragment, new NavigateFragment()) .add(R.id.receipts_fragment, new ReceiptsFragment()) .commit(); } </code></pre>
 

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