daimajia / daimajia/AndroidSwipeLayout
Update Conditional Layout for Row
- Dominant language
- Java
- Stars
- 12.3k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.