daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Update Conditional Layout for Row #405

Open ryanbennettvoid opened 7 years ago

ryanbennettvoid commented 7 years ago

With a standard ListView, you can have conditional layouts like so:

convertView = li.inflate(
        d.getStatus() == STATUS_COMPLETE ? R.layout.row_item_download_complete :
        d.getStatus() == STATUS_ERROR ? R.layout.row_item_download_error :
        R.layout.row_item_download,
        null
);

It does initially use the right view, but it doesn't update afterwords. The BaseSwipeAdapter's generateView isn't fired after notifyDataSetChanged is fired and it seems to be caching the view internally.

Manually firing generateView doesn't update the row either.

Using standard ListView techniques ( e.g. http://stackoverflow.com/questions/2123083/android-listview-refresh-single-row ) doesn't seem to work.

On the other hand, fillValues is fired after notifyDataSetChanged, but you can only modify the view given to you. Here's the hack I'm using to work around that inside fillValues:

if ( forceUpdate ) {

    ViewGroup newView = (ViewGroup) generateView( position, (ViewGroup) convertView.getParent() );

    ( (ViewGroup) convertView ).removeAllViews();

    for ( int i = 0; i < newView.getChildCount(); i++ ) {
        View v = newView.getChildAt( i );
        newView.removeView( v );
        ( (ViewGroup) convertView).addView( v );
    }

    forceUpdate = false;

}

Is there simpler way of just getting the adapter to re-render the whole row from scratch?