android - home screen widget text view not updating -


this code of program -

package com.nadeem.todos;  import android.app.pendingintent; import android.appwidget.appwidgetmanager; import android.appwidget.appwidgetprovider; import android.content.componentname; import android.content.context; import android.content.intent; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.widget.remoteviews;  public class todo_widget extends appwidgetprovider { private sqlitedatabase db; private todosqlitehelper dbhelper; string[] widget_title = { "", "", "", "", "", "" }; string[] widget_content = { "", "", "", "", "", "" }; public static string action_widget_refresh = "actionreceiverrefresh"; public static string action_widget_open = "actionreceiveropen";  @override public void onupdate(context context, appwidgetmanager appwidgetmanager,         int[] appwidgetids) {      intent intent = new intent(context, mainactivity.class);     pendingintent pendingintent = pendingintent.getactivity(context, 0,             intent, pendingintent.flag_update_current);      remoteviews views = new remoteviews(context.getpackagename(),             r.layout.widget_layout);     views.setonclickpendingintent(r.id.contentw2, pendingintent);     views.setonclickpendingintent(r.id.contentw3, pendingintent);     intent i1 = new intent(context, todo_widget.class);     i1.setaction(action_widget_refresh);      pendingintent pi = pendingintent.getbroadcast(context, 0, i1,             pendingintent.flag_update_current);     views.setonclickpendingintent(r.id.flip, pi);     views.setonclickpendingintent(r.id.contentw1, pi);     appwidgetmanager.updateappwidget(appwidgetids, views); }  @override public void onreceive(context context, intent intent) {     appwidgetmanager appwidgetmanager = appwidgetmanager             .getinstance(context);      int[] ids = appwidgetmanager.getinstance(context).getappwidgetids(             new componentname(context, todo_widget.class));     remoteviews views = new remoteviews(context.getpackagename(),             r.layout.widget_layout);     if (intent.getaction().equals(action_widget_refresh)) {         views.settextviewtext(r.id.titlew1, widget_title[3]);         views.settextviewtext(r.id.contentw1, widget_content[3]);         appwidgetmanager.updateappwidget(ids, views);      } else if (intent.getaction().equals(             appwidgetmanager.action_appwidget_update)) {         dbhelper = new todosqlitehelper(context);         db = dbhelper.getwritabledatabase();         string[] tablecolumns = new string[] { "_id", "title", "todo" };          int j = 0;          cursor cursor = db.query("todos", tablecolumns, null, null, null,                 null, null);         cursor.movetofirst();         while (!cursor.isafterlast()) {              if (j < 6) {                 widget_title[j] = cursor.getstring(1);                 widget_content[j] = cursor.getstring(2);             }             j++;              cursor.movetonext();         }         db.close();         final int n = ids.length;         (int = 0; < n; i++) {             int appwidgetid = ids[i];             views.settextviewtext(r.id.titlew1, widget_title[0]);             views.settextviewtext(r.id.titlew2, widget_title[1]);             views.settextviewtext(r.id.titlew3, widget_title[2]);             views.settextviewtext(r.id.contentw1, widget_content[0]);             views.settextviewtext(r.id.contentw2, widget_content[1]);             views.settextviewtext(r.id.contentw3, widget_content[2]);             appwidgetmanager.updateappwidget(appwidgetid, views);          }     }     super.onreceive(context, intent); }     } 

my problem text view in onrecieve method not updated when action_widget_refresh true. have set pending intent on text view when clicked text of text view (r.id.content1) changes. when click on text view text view dissappears. have no idea why happening. other code works fine.

every time call appwidgetmanager.updateappwidget(), removeviews pass in needs "contain complete representation of widget". means need set text textviews every time, not when text should change. setting text changes, you're losing text want remain same.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -