track which list items are expanded so when rebuilt (e.g. after

scrolling out of sight) the retain their state.  (Not preserved across
invocations of the activity.)
This commit is contained in:
Eric House 2014-06-23 08:03:48 -07:00
parent b34f701b1e
commit 91db8d9cdb
2 changed files with 19 additions and 7 deletions

View file

@ -85,6 +85,7 @@ public class DictsDelegate extends ListDelegateBase
private ListActivity m_activity;
private Set<String> m_closedLangs;
private Set<DictInfo> m_expandedItems;
private DictListAdapter m_adapter;
private boolean m_quickFetchMode;
@ -222,12 +223,12 @@ public class DictsDelegate extends ListDelegateBase
String name = info.m_name;
item.setText( name );
item.setCached( info );
item.setExpandedListener( DictsDelegate.this );
item.setExpanded( m_expandedItems.contains( info ) );
item.setComment( m_onServerStr );
item.setCached( info );
if ( m_selDicts.containsKey( name ) ) {
m_selDicts.put( name, item );
item.setSelected( true );
@ -462,6 +463,8 @@ public class DictsDelegate extends ListDelegateBase
m_closedLangs.addAll( Arrays.asList( closed ) );
}
m_expandedItems = new HashSet<DictInfo>();
m_locNames = getStringArray( R.array.loc_names );
m_noteNone = getString( R.string.note_none );
@ -970,14 +973,15 @@ public class DictsDelegate extends ListDelegateBase
}
//////////////////////////////////////////////////////////////////////
// XWListItem.ExpandedListener
// XWListItem.ExpandedListener interface
//////////////////////////////////////////////////////////////////////
public void expanded( XWListItem me, boolean expanded )
{
final DictInfo info = (DictInfo)me.getCached();
if ( expanded ) {
m_expandedItems.add( info ); // may already be there
LinearLayout view =
(LinearLayout)inflate( R.layout.remote_dict_details );
final DictInfo info = (DictInfo)me.getCached();
Button button = (Button)view.findViewById( R.id.download_button );
button.setOnClickListener( new View.OnClickListener() {
public void onClick( View view ) {
@ -999,6 +1003,7 @@ public class DictsDelegate extends ListDelegateBase
me.addExpandedView( view );
} else {
me.removeExpandedView();
m_expandedItems.remove( info );
}
}

View file

@ -80,6 +80,14 @@ public class XWListItem extends LinearLayout
setOnClickListener( this );
}
protected void setExpanded( boolean expanded )
{
m_expanded = expanded;
if ( null != m_expListener ) {
m_expListener.expanded( this, m_expanded );
}
}
protected void addExpandedView( View view )
{
if ( null != m_expandedView ) {
@ -178,9 +186,8 @@ public class XWListItem extends LinearLayout
{
if ( m_checkbox == view ) {
setSelected( m_checkbox.isChecked() );
} else if ( null != m_expListener ) {
m_expanded = !m_expanded;
m_expListener.expanded( this, m_expanded );
} else {
setExpanded( !m_expanded ); // toggle
}
}