2010-12-13 21 views
7

नीचे दिखाया गया है मेरी कक्षा का सरलीकृत संस्करण। मुझे ऑनसेसिव विधि में परेशानी हो रही है जो विजेट TextView को अद्यतन नहीं कर रहा है। यह logcat में सही जानकारी दिखाता है जो setTextViewText से पहले लाइन पर outputted है। मुझे यकीन नहीं है कि क्या गलत है और मेरे बालों को खींच रहा है (और मैं पहले से ही गंजा रहा हूं)।setTextViewText विजेट अपडेट नहीं कर रहा है

public class SnowWidget extends AppWidgetProvider { 

public static List<Article> mymtns = new ArrayList<Article>(); 
public static RemoteViews remoteViews; 
public static ComponentName thisWidget; 

public static String amount = ""; 
public static String mtn_name = ""; 
public static String desc = ""; 
public static String condition = ""; 
public static String[] type; 

public static int index = 0; 

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
    int[] appWidgetIds) 
{ 

    remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); 

    thisWidget = new ComponentName(context, SnowWidget.class); 

    // This one works fine 
    remoteViews.setTextViewText(R.id.snowwidget, mtn_name+ "\n"+ amount+"\"\n"+ condition); 

    /* Make the buttons work */ 

Intent next = new Intent(context, SnowWidget.class); 
next.setAction(ACTION_WIDGET_RECEIVER); 

PendingIntent nextPendingIntent = PendingIntent.getBroadcast(context, 0, next, 0); 
remoteViews.setOnClickPendingIntent(R.id.nextMtn, nextPendingIntent); 

/* END - Make the buttons work */ 

    appWidgetManager.updateAppWidget(thisWidget, remoteViews); 
} 

@Override 
public void onReceive(Context context, Intent intent) { 

    // check, if our Action was called 
    if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) { 
     if(mymtns.size() > 0) 
     { 

      // This show up correctly in logcat 
      Log.d("onReceive", "New Info => "+ mtn_name+ "\n"+ amount+"\"\n"+ condition); 
      // This never updates my widget 
      remoteViews.setTextViewText(R.id.snowwidget, mtn_name+ "\n"+ amount+"\"\n"+ condition); 

     } 
    } 

    super.onReceive(context, intent); 
} 

}

+1

उत्तर – Brombomb

उत्तर

20

मिले जवाब। remoteViews.setTextViewText पर कॉल करने के बाद आपको updateAppWidget पर कॉल के साथ विजेट को अपडेट करने की आवश्यकता है। मैंने जो कोड जोड़ा है वह नीचे दिखाया गया है।

AppWidgetManager manager = AppWidgetManager.getInstance(context); 
manager.updateAppWidget(thisWidget, remoteViews); 
+0

के लिए अद्यतन इस के लिए बहुत बहुत धन्यवाद! यह वर्णन करना मुश्किल है कि इस समस्या के कारण मुझे कितना सिरदर्द हुआ है। –

+3

मेरे पास यह कोड है और यह अभी भी काम नहीं कर रहा है .. हालांकि यह पहले था। मुझे कुछ नहीं पता किक्या हुआ? – xdumaine

+0

आप कोड की उन कुछ पंक्तियों को कहां जोड़ रहे हैं? मुझे लगता है कि मेरा विजेट काम नहीं कर रहा है। PendingIntent.getActivity (संदर्भ, 0, इरादे, 0) के बजाय : PendingIntent.getActivity (संदर्भ, 0, इरादे, PendingIntent.FLAG_UPDATE_CURRENT) – Si8

संबंधित मुद्दे