How to receive notifications when a key is pressed in any child view of a containing view
<p>I am writing an app that computes a "net income" number based on "additions to income" and "deductions from income." I have two different layouts--one for tablets and one for phones. The tablet version shows a much more detailed questionnaire and the phone version shows a shorter form.</p>

<p>Here's the XML for the "long form." I took out a bunch of TableRows for this posting because I didn't want to just have the XML blather on and on. Other than that, this is exactly what I'm using. (There are two tables, side by side).</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:id="@+id/input_layout"
    &gt;
    &lt;TableLayout android:layout_height="wrap_content" android:id="@+id/tableLayout0" android:layout_width="fill_parent"&gt;
      &lt;TableRow android:layout_width="wrap_content"&gt;

          &lt;!-- Table appearing on left side prompting for additions to income --&gt;
        &lt;TableLayout android:layout_height="wrap_content" android:id="@+id/tableLayout1" android:layout_width="fill_parent"&gt;
            &lt;TableRow android:id="@+id/tableRow0" android:layout_width="wrap_content"&gt;
                &lt;TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:id="@+id/textView1" android:text="@string/income"&gt;&lt;/TextView&gt;
            &lt;/TableRow&gt;
            &lt;TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;
                &lt;TextView style="@style/leftIndentText" android:id="@+id/textView2" android:text="@string/gross_income"&gt;&lt;/TextView&gt;
                &lt;EditText style="@style/NumericInput" android:id="@+id/textGrossIncome"&gt;
                    &lt;requestFocus&gt;&lt;/requestFocus&gt;
                &lt;/EditText&gt;
            &lt;/TableRow&gt;
            &lt;TableRow&gt;
                &lt;TextView style="@style/leftIndentText" android:text="@string/pay_frequency"/&gt;
                &lt;Spinner style="@style/Spinner" 
                    android:id="@+id/PayFrequency" 
                    android:entries="@array/pay_frequency_choices"/&gt;
            &lt;/TableRow&gt;
            &lt;TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;
                &lt;TextView style="@style/leftIndentText" android:id="@+id/textView3" android:text="@string/investment_income"&gt;&lt;/TextView&gt;
                &lt;EditText style="@style/NumericInput"  android:id="@+id/textInvestmentIncome"&gt;&lt;/EditText&gt;
            &lt;/TableRow&gt;
        &lt;/TableLayout&gt;

          &lt;!-- Table appearing on rightside prompting for deductions from income --&gt;
          &lt;TableLayout&gt;
            &lt;TableRow&gt;
                &lt;TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:id="@+id/textView1" android:text="@string/deductions"&gt;&lt;/TextView&gt;
            &lt;/TableRow&gt;
            &lt;TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;
                &lt;TextView style="@style/leftIndentText" android:id="@+id/textView3" android:text="@string/unreimb_bus_exp"&gt;&lt;/TextView&gt;
                &lt;EditText style="@style/NumericInput" android:id="@+id/textUnreimbBusExp"&gt;&lt;/EditText&gt;
            &lt;/TableRow&gt;
            &lt;/TableLayout&gt;
            &lt;/TableRow&gt;
        &lt;/TableLayout&gt;
&lt;/ScrollView&gt;
</code></pre>

<p>The calculations are done in a separate class that just addes up all the additions to income, subtracts the deductions from income, and provides a net number. I want the class that computes the answer to be updated each time the user leaves an input field. So my great vision was to have an onFocusChangeListener attached to each input field.</p>

<p>Here's the problem I'm facing. What I was hoping to do was figure out a way to get notified when any EditText view lost focus WITHOUT having to explicitly set an onFocusChangeListener on each EditText view. My reasoning is that this app deals with the laws in individual states and there are different inputs for each state. They all boil down to additions to and deductions from income.</p>

<p>I've been all over the Android developer forums and this site, and I just can't figure out how to do it. The path I went down, which hasn't worked, is to set an onFocusChangeListener on the TableView that contains the EditText views, but I haven't been able to get that to work.</p>

<p>The way I tried to do that is when the Fragment gets created and it's View is inflated, I added a callback at that point, i.e.</p>

<pre><code>public class InputFragment extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflator.inflate(R.layout.input_fragment_layout, container, false);
        View table = view.findViewById(R.id.tableLayout0);

        try
        {
            table.setFocusable(true);
            table.setOnFocusChangeListener(new OnFocusChangeListener()
            {
                @Override
                public void onFocusChange(View v, boolean hasFocus)
                {
                    Log.e("TJD1", "Focus change event");
                }

            });
        }
        catch (Exception e)
        {
            Log.e("TJD1", "Error: " + e.toString());
        }

        return view;
    }
}
</code></pre>

<p>I also considered trying to iterate over each of the EditText views when the Fragment is created, but I can't figure out how to do that either.</p>

<p>Any pointers in the right direction would be so very helpful. Thank you.</p>
