Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public class MainActivity extends Activity implements OnClickListener{ private int mAppWidgetId; private RemoteViews rv; private AppWidgetManager appWidgetManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rv = new RemoteViews(this.getPackageName(), R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); Button button2 = (Button)findViewById(R.id.button2); AnalogClock cos1 = (AnalogClock)findViewById(R.id.analogClock1); AnalogClock cos2 = (AnalogClock)findViewById(R.id.analogClock2); button1.setOnClickListener(this); button2.setOnClickListener(this); } @Override public void onClick(View view) { 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(this); appWidgetManager.updateAppWidget(mAppWidgetId, rv); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } </code></pre> <p>}</p> <p>I added few fixes and does not throw an error. :)</p>
 

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