public void onClick(View v) { final Context context = ExampleAppWidgetConfigure.this; // When the button is clicked, save the string in our prefs and return that they // clicked OK. String titlePrefix = mAppWidgetPrefix.getText().toString(); saveTitlePref(context, mAppWidgetId, titlePrefix); // Push widget update to surface with newly set prefix AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ExampleAppWidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId, titlePrefix); // Make sure we pass back the original appWidgetId Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } };
public void onClick(View v) { final Context context = ExampleAppWidgetConfigure.this; // When the button is clicked, save the string in our prefs and return that they // clicked OK. String titlePrefix = mAppWidgetPrefix.getText().toString(); saveTitlePref(context, mAppWidgetId, titlePrefix); // Push widget update to surface with newly set prefix AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ExampleAppWidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId, titlePrefix); // Make sure we pass back the original appWidgetId Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } };
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // Set the result to CANCELED. This will cause the widget host to cancel // out of the widget placement if they press the back button. setResult(RESULT_CANCELED); // Set the view layout resource to use. setContentView(R.layout.appwidget_configure); // Find the EditText mAppWidgetPrefix = (EditText)findViewById(R.id.appwidget_prefix); // Bind the action for the save button. findViewById(R.id.save_button).setOnClickListener(mOnClickListener); // Find the widget id from the intent. Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } // If they gave us an intent without the widget id, just bail. if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); } mAppWidgetPrefix.setText(loadTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId)); }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // Set the result to CANCELED. This will cause the widget host to cancel // out of the widget placement if they press the back button. setResult(RESULT_CANCELED); // Set the view layout resource to use. setContentView(R.layout.appwidget_configure); // Find the EditText mAppWidgetPrefix = (EditText)findViewById(R.id.appwidget_prefix); // Bind the action for the save button. findViewById(R.id.save_button).setOnClickListener(mOnClickListener); // Find the widget id from the intent. Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } // If they gave us an intent without the widget id, just bail. if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); } mAppWidgetPrefix.setText(loadTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId)); }