Android - update widget text
Posted
by david
on Stack Overflow
See other posts from Stack Overflow
or by david
Published on 2010-05-18T20:13:02Z
Indexed on
2010/05/18
20:50 UTC
Read the original article
Hit count: 175
Hi, i have 2 questions about widgets update
- I have 2 buttons and i need to change one button text when i press the other one, how can i do this?
The first time i open the widget it calls the onUpdate method, but it never calls it again. I need to update the widget every 2 seconds and i have this line in the xml.
android:updatePeriodMillis="2000"
Do i need a service or should it works just with the updatePeriodMillis tag?
onUpdate method
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.newswidget); Intent intent = new Intent(context, DetalleConsulta.class); intent.putExtra(DetalleConsulta.CONSULTA_ID_NAME, "3"); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.btNews, pendingIntent); /* Inicializa variables para llamar el controlador */ this.imei = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); this.controlador = new Controlador(this.imei); try { this.respuestas = this.controlador.recuperarNuevasRespuestas();
} catch (PersistenciaException e) { //TODO manejar error } appWidgetManager.updateAppWidget(appWidgetIds, views);if(this.respuestas != null && this.respuestas.size() > 0){ Iterator<Consulta> iterRespuestas = this.respuestas.iterator(); views.setTextViewText(R.id.btNews, ((Consulta)iterRespuestas.next()).getRespuesta()); }
thx a lot!!!
© Stack Overflow or respective owner