Note that there are some explanatory texts on larger screens.

plurals
  1. POAppWidget won't work
    primarykey
    data
    text
    <p>I'm using a configuration activity to toggle visibilty of different views in the xml file using RemoteViews. At first i thought, since the configuration activity is called before the widget is set, i wouldnt need to update, so i used : </p> <pre><code>package com.example.test.clock.one; import android.app.Activity; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.RemoteViews; public class chooseract extends Activity { int mAppWidgetId; RemoteViews rv; AppWidgetManager appWidgetManager; Context context; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void buttonhandler(View view) { rv = new RemoteViews(context.getPackageName(), R.layout.activity_main); Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID); } switch(view.getId()) { case R.id.button1: { rv.setViewVisibility(R.id.analogClock1, View.VISIBLE); rv.setViewVisibility(R.id.analogClock2, View.INVISIBLE); finish(); break; } case R.id.button2: { rv.setViewVisibility(R.id.analogClock1, View.INVISIBLE); rv.setViewVisibility(R.id.analogClock2, View.VISIBLE); finish(); break; } } } } </code></pre> <p>but that just sets a blank widget (default visibility is INVISIBLE) then i tried updating the appwidget after toggling visibility using</p> <pre><code>package com.example.test.clock.one; import android.app.Activity; import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.RemoteViews; public class chooseract extends Activity { int mAppWidgetId; RemoteViews rv; AppWidgetManager appWidgetManager; Context context; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void buttonhandler(View view) { rv = new RemoteViews(context.getPackageName(), R.layout.activity_main); Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID); } switch(view.getId()) { case R.id.button1: { rv.setViewVisibility(R.id.analogClock1, View.VISIBLE); rv.setViewVisibility(R.id.analogClock2, View.INVISIBLE); break; } case R.id.button2: { rv.setViewVisibility(R.id.analogClock1, View.INVISIBLE); rv.setViewVisibility(R.id.analogClock2, View.VISIBLE); break; } } AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); appWidgetManager.updateAppWidget(mAppWidgetId, rv); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } } </code></pre> <p>but this just force closes when i touch the buttons with a NullPointerException Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload