Laser
Laser

Reputation: 6960

Add button to Android Widget dynamically

I wan't to add button to android widget dynamically.
I've tried to do it by following way from main Activty:

  Button a = new Button(this);
  a.setText("Pushme");
  RelativeLayout rl = (RelativeLayout)findViewById(R.id.llay);
  rl.addView(a);

RelativeLayout here it's widget layout.

From AppWidgetProvider custom class I cant do it too, cause I'm unable to create there button.

Is there any solution?

Upvotes: 0

Views: 1850

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007359

You can call addView() on a RemoteViews to add a nested RemoteViews.

Or, define all your buttons in your base layout that you use with RemoteViews, with some buttons initially set to android:visibility="gone". Then, use setViewVisibility() on the RemoteViews to make them visible as desired.

Upvotes: 1

Related Questions