From eda1e89e3e96ada13eee71f9d4905fbca7ce3811 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 4 Jan 2016 20:40:47 -0800 Subject: [PATCH] replace empty-list-explanation functionality that went away when I stopped inheriting from ListActivity. --- .../eehouse/android/xw4/InviteDelegate.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java index 251118d3c..284df01c7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/InviteDelegate.java @@ -27,12 +27,15 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; +import android.widget.ListView; import android.widget.TextView; +import android.view.ViewGroup; import junit.framework.Assert; abstract class InviteDelegate extends ListDelegateBase - implements View.OnClickListener { + implements View.OnClickListener, + ViewGroup.OnHierarchyChangeListener { public static final String DEVS = "DEVS"; public static final String COUNTS = "COUNTS"; @@ -43,6 +46,8 @@ abstract class InviteDelegate extends ListDelegateBase protected Button m_rescanButton; protected Button m_clearButton; private Activity m_activity; + private ListView m_lv; + private View m_ev; public InviteDelegate( Delegator delegator, Bundle savedInstanceState, int layoutID ) @@ -66,9 +71,19 @@ abstract class InviteDelegate extends ListDelegateBase TextView descView = (TextView)findViewById( desc_id ); descView.setText( descTxt ); + m_lv = (ListView)findViewById( android.R.id.list ); + m_ev = findViewById( android.R.id.empty ); + if ( null != m_lv && null != m_ev ) { + m_lv.setOnHierarchyChangeListener( this ); + showEmptyIfEmpty(); + } + tryEnable(); } + //////////////////////////////////////// + // View.OnClickListener + //////////////////////////////////////// public void onClick( View view ) { if ( m_okButton == view ) { @@ -87,6 +102,24 @@ abstract class InviteDelegate extends ListDelegateBase } } + //////////////////////////////////////// + // ViewGroup.OnHierarchyChangeListener + //////////////////////////////////////// + public void onChildViewAdded( View parent, View child ) + { + showEmptyIfEmpty(); + } + public void onChildViewRemoved( View parent, View child ) + { + showEmptyIfEmpty(); + } + + private void showEmptyIfEmpty() + { + m_ev.setVisibility( 0 == m_lv.getChildCount() + ? View.VISIBLE : View.GONE ); + } + abstract void tryEnable() ; abstract void listSelected( String[][] devsP, int[][] countsP ); abstract void scan();