title: android widget update text using activity
body: <p>I want to update widget item when I Add or Remove item using activity in my WelcomeWidget class onReceive() as </p>
  
  <pre><code> public void onReceive(Context context, Intent intent) { 
   setup(context); 
   if (datalist.size() != 0)
   { 
   if (intent.getAction().equals(ACTION_NEXT_TIP)) {
       mMessage = getNextMessageIndex();
       SharedPreferences.Editor pref = context.getSharedPreferences( 
        PREFS_NAME,            0).edit(); 
       pref.putInt(PREFS_TIP_NUMBER, mMessage); 
      pref.commit(); 
      refresh();
      } 
      else if (intent.getAction().equals(ACTION_SETTING))
       {
       Intent articleIntent = new Intent(context,
       LoremActivity.class);                 
        articleIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  
      context.startActivity(articleIntent);      
    } else {
  
        refresh();        
    }  }   }
  </code></pre>
  
  <p>where refresh method is as :</p>
  
  <pre><code>private void refresh() {
  
       RemoteViews rv = buildUpdate(mContext); 
       for (int i : mWidgetIds) {
        mWidgetManager.updateAppWidget(i, rv); 
           }
  </code></pre>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <p>Using Animation as :</p>
  
  <pre><code>AnimationSet farsiTelLogoAnimation = new AnimationSet(true);
           RotateAnimation rotate = new RotateAnimation(0, 360,
          RotateAnimation.RELATIVE_TO_SELF, 0.5f,
          RotateAnimation.RELATIVE_TO_SELF, 0.5f);      
          rotate.setFillAfter(true);     
         rotate.setDuration(1000);
          farsiTelLogoAnimation.addAnimation(rotate);    
  </code></pre>
  
  <p>}</p>
  
  <p>getting message index
        private int getNextMessageIndex() {</p>
  
  <pre><code>  return (mMessage + 1) % datalist.size();
  
       }
  </code></pre>
  
  <p>where buildUpdate () method is as </p>
  
  <pre><code>     public RemoteViews buildUpdate(Context context) { 
  
            RemoteViews updateViews =
           new  RemoteViews(context.getPackageName(), R.layout.widget);
  
      // Action for tap on bubble        
         Intent bcast = new Intent(context,
         WelcomeWidget.class);
         bcast.setAction(ACTION_NEXT_TIP);
          PendingIntent pending = PendingIntent.getBroadcast(context, 
            0, bcast, PendingIntent.FLAG_UPDATE_CURRENT); 
        updateViews.setOnClickPendingIntent(R.id.widget, pending);
  
         // RemoteViews updateViews1 = new
        RemoteViews(context.getPackageName(), // R.id.setting);
  
         Intent bcast1 = new Intent(context, WelcomeWidget.class);
          bcast1.setAction(ACTION_SETTING);       PendingIntent pending1 =
        PendingIntent.getBroadcast(context, 
            0, bcast1,      PendingIntent.FLAG_UPDATE_CURRENT);       
        updateViews.
        setOnClickPendingIntent(R.id.setting, pending1);
  
          // Tip bubble text      if (mMessage &gt;= 0) {            // String[] parts =
  
       sNewlineRegex.split(mTips[mMessage], 2); 
       String to = datalist.get(mMessage).getFrom(); 
       String from =       datalist.get(mMessage).getTo();
        String rate = datalist.get(mMessage).getRate();
  
    // Look for a callout graphic referenced in the text            Matcher m =
  
       sDrawableRegex.matcher(to); 
      if (m.find()) {
        String imageName = m.group(1);
        int resId = context.getResources().getIdentifier(
  
        imageName, null, context.getPackageName());
        // updateViews.setImageViewResource(R.id.tip_callout, resId);
        // updateViews.setViewVisibility(R.id.tip_callout,
        // View.VISIBLE);
        to = m.replaceFirst("");            } else {
        // updateViews.setImageViewResource(R.id.tip_callout, 0);0
        // updateViews.setViewVisibility(R.id.tip_callout, View.GONE);          }
  
      updateViews.setTextViewText(R.id.to, to);
      updateViews.setTextViewText(R.id.from, from);
      updateViews.setTextViewText(R.id.rate, rate);
      updateViews.setTextViewText(
            R.id.tip_footer,
            context.getResources().getString(R.string.pager_footer,
                    (1 + mMessage), datalist.size()));              
               updateViews.setViewVisibility(R.id.tip_bubble, View.VISIBLE);   
  
              }
             else { 
                    updateViews.setViewVisibility(R.id.tip_bubble, View.INVISIBLE);
                 }
  
             return updateViews;    
  
            }
  </code></pre>
  
  <p>where Button click event reload widget</p>