I have several very similar layouts for my AppWidget, in fact differing only in the rotation of one of the TextView elements (I select the appropriate layout based on the screen orientation).
So rather than repeat the same stuff multiple times (I hate repetition) I thought I'd try and tidy things up by Re-using Layouts with <include/>.
The problem comes when I'm trying to reference particular elements of the layout by ID. Where the element is in the included layout xml, for non-AppWidget layouts I've used a method described here, where a two-tier approach is used...
In the "parent" layout:
<include layout="@layout/my_layout" android:id="@+id/textview_layout" />
In the code:
TextView tv = (TextView)findViewById(R.id.textview_layout).findViewById(R.id.textview);
tv.setText("test");
... where the ID of the TextView in the "child" layout is textview. So it's a two-stage approach where you first reference the View containing the TextView that you want, and then you reference the TextView off that.
But for AppWidgets, rather than dealing directly with the TextView, you have to do everything through a RemoteViews.
So instead of:
TextView textView = (TextView)findViewById(viewId);
textView.setText("text");
you would have to do:
remoteViews.setTextViewText(viewId, "text");
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
Given that the interface into the RemoteViews is by way of passing in a single (direct) view ID, how would you reference an element in an included file?