0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

But I wan't to generate button in runtime is it possible?
@Pepelac: I believe that I covered this in my answer. Note that what you want may not work very well, as the app widget's overall size will not change, and so your added button may cause other things in your app widget to shrink.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.