Tuesday, February 25, 2014

Android: "No Resource Found" & nextFocusDown

I received a mysterious Android XML error earlier today:

error: Error: No resource found that matches the given name (at 'nextFocusDown' with value '@id/current_calculation_display').

This requires a bit of background.

My application has three layout files:
  1. activity_calculator_horizontal.xml
  2. activity_calculator_small_vertical.xml
  3. activity_calculator_vertical.xml
All three files have a parent node: LinearLayout or ScrollView depending on layout. Each contains a TextView with attribute android:id="@+id/current_calculation_display".

This error occured when setting the android:nextFocusDown attribute in the 'horizontal' activity's parent node to "@id/current_calculation_display". I did this with the 'vertical' and 'small_vertical' layouts without issue.

The problem is that, in the 'horizontal' activity, the 'current_calculation_display' ID doesn't exist yet! This isn't a problem for the other two files because the ID gets created in the 'horizontal' activity. I tested this behavior by adding a (mostly blank) activity with the current_calculation_display TextView.

Using android:nextFocusDown="@+id/current_calculation_display" fixes the problem.

No comments:

Post a Comment