I am working with modified version of sample WeatherListWidget to get a better understanding of App Widgets. Things are fine – except when I try to replace the dark_widget_item and light_widget_item layout files with slightly more complex layout files. Here is original layout:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_item"
android:layout_width="match_parent"
android:layout_height="46dp"
android:paddingLeft="25dp"
android:gravity="center_vertical"
android:background="@drawable/item_bg_light"
android:textColor="#e5e5e1"
android:textSize="24sp" />
I would like to be able to have multiple text lines. But:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_item"
android:background="@drawable/item_bg"
android:layout_width="match_parent"
android:layout_height="46dp"
android:paddingLeft="25dp">
<TextView android:id="@+id/type_string"
android:textColor="#666666"
android:textSize="20sp" />
<TextView android:id="@+id/title_string"
android:textColor="#666666"
android:textSize="18sp" />
</LinearLayout>
fails.
In fact, it results in “Sorry! The application Launcher (process com.android.launcher) has stopped unexpectedly. Please try again. Force close”.
Reinstating TextView widget_item.xml fixes this. I suspect that part of the problem is how I reference RemoteViews in WeatherWidgetService.getViewAt() – but I am getting very little help from DDMS or LogCat or anything else.
Thanks guys, I got the notification. (SO requires a username with
length > 2, hence the dot)Answer as per comment:
I don’t see any
layout_widthandlayout_heightattributes for both of the TextViews in your LinearLayout – they are mandatory. Also, if you want the two TextViews to be above eachother, addandroid:orientation="vertical"to the LinearLayout. And just to the record, you can break a CharSequence to multiple lines in a single TextView by adding “\n” inbetween the different elements.If you’re going to include an image as well, then you’re probably better off with a LinearLayout than a single TextView indeed, although you could potentially use the intrinsic drawable option of the latter. That could get a little messy though, especially if you’re planning on using different styles for the different lines of text… Not impossible, but I’d stick with the LinearLayout. 😉