Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I notify views owned by a custom adapter that they're going away?
    primarykey
    data
    text
    <p>In my current project I've extended BaseAdapter (using the tutorial EfficientAdapter as a guide) to handle a couple of different custom cell types, each with its own custom view. Some of those cell types start asynchronous operations (playing and recording media, for example). I'd like to pause them when the activity they belong to goes away (which several other cell types can cause to happen). Is there any way to notify a particular view that the ListActivity to which it "belongs" is going away?</p> <p>My first thought was to iterate over the views in the <code>onPause()</code> method of the activity:</p> <pre><code>@Override public void onPause() { super.onPause(); for (int i = 0; i &lt; adapter.getCount(); i++) { CustomCellHolder holder = adapter./* Some magic goes here */; holder.handlePause(); } } </code></pre> <p>but I can't figure out how to iterate over the views owned by the list adapter. Is there a way to do that, or am I barking up the wrong tree?</p> <p>If it's relevant, my getView method looks something like this:</p> <pre><code>public View getView(final int position, View convertView, ViewGroup parent) { CustomCellHolder holder; if (convertView == null) { /* Create and cache a new view */ holder = newHolderForItem(someArrayListOfObjects.get(position)); holder.setItem(feature.attributes.get(position)); holder.setActivity(MyListActivity.this); convertView = holder.getView(); } else { /* Load a cached view */ holder = (CustomCellHolder) convertView.getTag(); holder.setItem(feature.attributes.get(position)); holder.setActivity(MyListActivity.this); } holder.doSomeStuff(); return convertView; } </code></pre>
    singulars
    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.
    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