Been stuck with this for a little while now, and I have found a number of solutions but I can't seem to get it right.
What I want to do, is to simply be able to add a few textviews dynamically to my widget during runtime, so that the widget will stay wrapped around the content (as opposed to having all textviews defined in the main layout from the start, and then simply have them empty when I don't need them. This would simply add a bunch of empty space in the widget it seems, which I want to avoid). I currently have two layout files, one main widget_layout and one widget_row (the row contains the views that I want to add to the main one during runtime) widget_layout.xml <?xml version="1.0" encoding="utf-8"?> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" > android:orientation="vertical" > android:id="@+id/layout" > android:layout_width="150dp" > android:layout_height="wrap_content" > android:background="@drawable/widgetshape"> > > <TextView > android:id="@+id/status" > style="@android:style/TextAppearance.Small" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:layout_margin="4dip" > android:gravity="center_horizontal" /> > </LinearLayout> > widget_row <?xml version="1.0" encoding="utf-8"?> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" > android:layout_width="match_parent" > android:layout_height="match_parent" > android:orientation="horizontal" > android:id="@+id/row" > > > <TextView > android:id="@+id/text" > style="@android:style/TextAppearance.Small" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:layout_margin="4dip" > android:gravity="center_horizontal" /> > > <TextView > android:id="@+id/value" > style="@android:style/TextAppearance.Small" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:layout_margin="4dip" > android:gravity="center_horizontal" /> > </LinearLayout> > And then some code I tried remoteViews.setTextViewText(R.id.status, Html.fromHtml("<b>Wifi:</b> " + > WifiSSID)); > > RemoteViews newView = new RemoteViews(context.getPackageName(), > R.layout.widget_row); > newView.setTextViewText(R.id.text, "entext"); > newView.setTextViewText(R.id.value, "ettvarde"); > remoteViews.addView(R.id.layout, newView); > The first solution that I tried didn't involve the widget_row.xml file, as I tried to create all the views directly in the code and then add them to the remoteview, but I later found some documentation that suggested that all views need to be predefined in XML before added, dynamically or not. If there is anyone who could shed some light on this issue, I would greatly appreciate it :-) -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en