Note that there are some explanatory texts on larger screens.

plurals
  1. POListView not Repainting from OnClickListener
    text
    copied!<p>I have a button that should sort a ListView using a custom adapter. The button listener is as follows:</p> <pre><code>collectionSort.setOnClickListener(new OnClickListener() { public void onClick(View v) { sortOrder = -sortOrder; Log.d("DBGINF", "Sort Order: " + sortOrder); m.sortByTitles(sortOrder); m.notifyDataSetChanged(); }); </code></pre> <p>The sort order changes as it should, and the data in the array is sorted, the actual view is never updated by the notifyDataSetChanged though. Here's the sortByTitles() method:</p> <pre><code>public void sortByTitles(int dir) { if (dir &gt; 0) { sort(new StringComparator()); } else if (dir &lt; 0) { sort(new ReverseStringComparator()); } Log.d("Data Set: ", this.getItem(0) + ""); } </code></pre> <p>The <code>notifyDataSetChanged()</code> doesn't ever update the view inside an <code>OnClickListener</code>, but always works properly <b>outside</b> one of the OnClickListeners. What am I doing wrong?</p> <p><strong>EDIT</strong></p> <p>Here is the constructor in the Adapter class:</p> <pre><code>public MainMenuArrayAdapter(Context context, CollectionObject[] objects) { super(context, R.layout.mainmenurow, objects); myContext = context; } </code></pre> <p>And here's how it gets initialized in the onCreate() method of the Activity:</p> <pre><code>CollectionObject[] sample = new CollectionObject[] { c1, c2, c3, c4, c5, c6 }; final MainMenuArrayAdapter m = new MainMenuArrayAdapter(this, sample); </code></pre> <p>Where c1 - c6 are just some temporary CollectionObjects for testing.</p>
 

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