Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7083125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:08:22+00:00 2026-05-28T07:08:22+00:00

currently, i’m adding elements dynamically to my widget using the following: RemoteViews views =

  • 0

currently, i’m adding elements dynamically to my widget using the following:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_design);

RemoteViews newView = new RemoteViews(context.getPackageName(), R.layout.widget_item);
views.addView(R.id.view_container, newView);

but how can I dynamically add margins, weights, and other properties to the added elements?

currently i have tried (using code I have found from different sites):

LinearLayout item = (LinearLayout) ((Activity) context).findViewById(R.id.widgetItem);
MarginLayoutParams marginParams = new MarginLayoutParams(item.getLayoutParams());
marginParams.setMargins(10, 50, 4, 5);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(marginParams);
item.setLayoutParams(layoutParams);

but this force-closes

LogCat:

09-10 22:01:55.283: ERROR/AndroidRuntime(30060): FATAL EXCEPTION: main
09-10 22:01:55.283: ERROR/AndroidRuntime(30060):
java.lang.RuntimeException: Unable to start receiver
com.example.test.HomeWidget: java.lang.ClassCastException:
android.app.ReceiverRestrictedContext 09-10 22:01:55.283:
ERROR/AndroidRuntime(30060): at
android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
09-10 22:01:55.283: ERROR/AndroidRuntime(30060): at
android.app.ActivityThread.access$3200(ActivityThread.java:125) 09-10
22:01:55.283: ERROR/AndroidRuntime(30060): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
09-10 22:01:55.283: ERROR/AndroidRuntime(30060): at
android.os.Handler.dispatchMessage(Handler.java:99) 09-10
22:01:55.283: ERROR/AndroidRuntime(30060): at
android.os.Looper.loop(Looper.java:123) 09-10 22:01:55.283:
ERROR/AndroidRuntime(30060): at
android.app.ActivityThread.main(ActivityThread.java:4627) 09-10
22:01:55.283: ERROR/AndroidRuntime(30060): at
java.lang.reflect.Method.invokeNative(Native Method) 09-10
22:01:55.283: ERROR/AndroidRuntime(30060): at
java.lang.reflect.Method.invoke(Method.java:521) 09-10 22:01:55.283:
ERROR/AndroidRuntime(30060): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
09-10 22:01:55.283: ERROR/AndroidRuntime(30060): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 09-10
22:01:55.283: ERROR/AndroidRuntime(30060): at
dalvik.system.NativeStart.main(Native Method) 09-10 22:01:55.283:
ERROR/AndroidRuntime(30060): Caused by: java.lang.ClassCastException:
android.app.ReceiverRestrictedContext 09-10 22:01:55.283:
ERROR/AndroidRuntime(30060): at
com.example.test.HomeWidget.onUpdate(HomeWidget.java:37) 09-10
22:01:55.283: ERROR/AndroidRuntime(30060): at
android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:61)
09-10 22:01:55.283: ERROR/AndroidRuntime(30060): at
android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
09-10 22:01:55.283: ERROR/AndroidRuntime(30060): … 10 more

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:08:23+00:00Added an answer on May 28, 2026 at 7:08 am
    LinearLayout layoutParams = item.getLayoutParams();
    layoutParams.setMargins(10, 50, 4, 5);
    item.setLayoutParams(layoutParams);
    

    Somehow creating new LayoutParams always causes such error. I think, there remain some fields unset. Only copy the existing ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I using the following code to get my JSON output from MySQL. <?php
Currently we have a project with a standard subversion repository layout of: ./trunk ./branches
Currently, I am developing a product that does fairly intensive calculations using MS SQL
Currently I am adding object by creating it like: type TRecord = class private
Currently i'm having trouble using two functions in my -(void)viewDidLoad , both of these
Currently have the following expression: @[TMS_Dest] + \\ + @[TMS_Rename] + (DT_WSTR,4)DatePart(yyyy, GetDate()) +
I want use html5's new tag to play a wav file (currently only supported
Currently I insert a new relationship by everytime checking, if it doesn't exist: unless
Currently I am using a pretty basic function to pre-load images: function preload(arrayOfImages) {
Currently I do like this: IndexSearcher searcher = new IndexSearcher(lucenePath); Hits hits = searcher.Search(query);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.