Reputation: 2142
i have 2 questions about widgets update
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();
if(this.respuestas != null && this.respuestas.size() > 0){
Iterator<Consulta> iterRespuestas = this.respuestas.iterator();
views.setTextViewText(R.id.btNews, ((Consulta)iterRespuestas.next()).getRespuesta());
}
} catch (PersistenciaException e) {
//TODO manejar error
}
appWidgetManager.updateAppWidget(appWidgetIds, views);
thx a lot!!!
Upvotes: 1
Views: 8518
Reputation: 126465
yes that changed since donut(1.6) to avoid your battery will be consumed shortly.
Hey David the next time try to put your other question in different thread to be accord with stackoverflow.com =)
to update the text from another button...
final Button btn1 = (Button) this.findViewById(R.id.Button01);
final Button btn2 = (Button) this.findViewById(R.id.Button02);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
btn2.setText("Button1 changed your text!");
}
});
Upvotes: 0
Reputation: 2142
Handling User Interaction with Android App Widgets
I tried it and it works.
i hope this help others!!!
Upvotes: 1