https://custom-analog-clock.googlecode.com/svn/trunk/
https://github.com/MadyZaid/Android-widget-Custom-Analog-Clock.git Please help me make this code better 2012/8/22 Piotrek Skowronek <[email protected]> > Hi > > I'm writing Analog Clock widget and it doesn't want to change layout at > runtime. Problem is that clock actually changes layout but only ONCE. Every > next onReceive() method calling is effectless. > > public class Widget extends AppWidgetProvider > { > public void onReceive(Context context, Intent intent) > { > String action = intent.getAction(); > if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) > { > RemoteViews views = new > RemoteViews(context.getPackageName(), R.layout.widget); > > Intent _intent = new Intent(context, MainActivity.class); > PendingIntent pendingIntent = > PendingIntent.getActivity(context, 0, _intent, 0); > views.setOnClickPendingIntent(R.id.Widget, pendingIntent); > > Random r = new Random(); > int i = r.nextInt( 2 ); > > if ( i > 0 ) > { > Log.d( "Widget", "Blue" ); > views.setImageViewResource( R.id.AnalogClock, > R.drawable.widgetdial_blue ); > } > else > { > Log.d( "Widget", "Black" ); > views.setImageViewResource( R.id.AnalogClock, > R.drawable.widgetdial ); > } > > > AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), > views); > } > } > } > > Provider is simply notified by onItemClick action as debugger confirms: > > public void onItemClick(AdapterView<?> parent, View view, int > position, long id) > { > Intent intent = new Intent( > AppWidgetManager.ACTION_APPWIDGET_UPDATE ); > sendBroadcast( intent ); > > Toast.makeText(getApplicationContext(), ((TextView) > view).getText(), Toast.LENGTH_SHORT).show(); > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

