Sunday 15 January 2012

java - ArrayAdapter - how do I stop getView calls? -


How do I stop the getView call, unless I change the dataset and do not call?

My problem:

I have a textfield that filters the adapter on textAvents if I change the text multiple times, then I get anAntxOutOfBoode exception because getView is still the adapter's Accessing the list, while the second time the filtering operation is already running.

Then the ATM goes like this:

  1. Filter in the background + Notify the data set
  2. Many times called GetView < / Li>
  3. While the next filter is being processed, due to the first filter, GetView is still being called in the background but due to list access, GetView gets an exception (filtering operation changes list). So I want to stop GetView calls and then start any filter operation.

    Edit:

    If I think the filter thread is active?

    Edit:

    Correctly relevant adapter code:

      @ Override protected filterReturning filtering (Charsimension barrier) {filterLock.acquireUninterruptibly (); FilterResults r = New FilterResults (); & Lt; T & gt; Item = null; M_Filter = Handicap; If (obstruction == faucet / * textualis empty (interrupt) * /) {// ar // asymmetric / da // unexpected nctity item = M_allimes; } And {items = m_FilteredItems; Items.clear (); Synchronize (sync) {for (t item: m_AllItems) {if (DynamicArrayAdapter.this.filter (item, constraint)) {items.add (item); }}}} R.values ​​= items; Arconton = Itemsize (); Return r; } @SuppressWarnings ("uncheck") @ Override protected zero published (squared barrier, filter result result) {m_Items = (list & lt; T & gt;) results.values; NotifyDataSetChanged (); FilterLock.release (); }   

    This is the filter that spreads by filter. M_Items and m_AllItems are used in adapters (first filtered, second unfiltered). As you can see that they have not been modified for the filtering (), the filter lock is a size 1 semaphore, so 2 filters are being handled at the same time.

    EDIT2:

    Also, in my on-test switch I can assure you that I do not modify the adapter either in any way, In the method which is called "PerformFiltering ()

    Changing the adapter not replaced by the UDI thread is your problem If you modify all your adapter UI threads then this will not happen because this is happening after the second.

    You can make heavy processing at a different thread but when you change the adapter that you have to do it on the UI thread using a handler or for example:

     < Code> // Really heavy filtering process RunOnYuththread (new Runnabal () (run from public zero) {// Change the contents of adapters // Now we are informing that the data has changed MAdapter.notifyDataSetChanged ();} });   

    After viewing your code: As LucasProog says, you should not change the list directly from the second thread, but the copy of the list should be used. What happens is that listView accepts a list with the size of X but you have already changed it to the size of the Wi and ListView did not know about it, to work on a copy of your item list After you have done, and after you do, post the UI thread on a Runnable that change the list of items in the adapter and call NotifyDataSetChanged () , this It was in that you list and you have to adapter With will not struggle.

No comments:

Post a Comment