The problem of the beginner


  1. carriera

    carriera New Member

    Hi,

    Learning the basics of android I'm trying to connect the two found on the web apps. One shows a widget with two lines of text other connects to the network and retrieves the XML file.

    The program compiles correctly and shows the result in the emulator (Eclipse), while on the phone (Samsung Ace - Android 2.3.6) I only have the default "Hello widget!" the declaration of variables (strings.xml).

    Can someone hovers me what I'm doing wrong.
    Enclosed is the code:
    Code (Text):
    1. package org.me.zachodnik;
    2.  
    3. import android.appwidget.AppWidgetManager;
    4. import android.appwidget.AppWidgetProvider;
    5. import android.content.ComponentName;
    6. import android.content.Context;
    7. import android.sax.Element;
    8. import android.widget.RemoteViews;
    9. import java.io.IOException;
    10. import java.io.StringReader;
    11. import java.io.UnsupportedEncodingException;
    12. import java.net.MalformedURLException;
    13. import java.util.Timer;
    14. import java.util.TimerTask;
    15. import javax.xml.parsers.DocumentBuilder;
    16. import javax.xml.parsers.DocumentBuilderFactory;
    17. import javax.xml.parsers.ParserConfigurationException;
    18. import org.apache.http.HttpEntity;
    19. import org.apache.http.HttpResponse;
    20. import org.apache.http.client.methods.HttpPost;
    21. import org.apache.http.impl.client.DefaultHttpClient;
    22. import org.apache.http.util.EntityUtils;
    23. import org.w3c.dom.Document;
    24. import org.w3c.dom.Node;
    25. import org.w3c.dom.NodeList;
    26. import org.xml.sax.InputSource;
    27. import org.xml.sax.SAXException;
    28.  
    29.  
    30.     public class Zachodnik extends AppWidgetProvider {
    31.     //private AppWidgetManager appWidgetManager;
    32.  
    33.         String Wsch;
    34.        
    35.         @Override
    36.         public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    37.             Timer timer = new Timer();          
    38.  
    39.             String xml = getXML("http://mywwwsite.asd/rss/asd.xml");
    40.             Document doc = XMLfromString(xml);
    41.             NodeList nodes = doc.getElementsByTagName("result");
    42.  
    43.            
    44.             Wsch = nodes.getLength() + "";
    45.             timer.scheduleAtFixedRate(new ZachodyWschody(context, appWidgetManager),100, 10000);
    46.  
    47.         }
    48.  
    49.         private class ZachodyWschody extends TimerTask{
    50.  
    51.             RemoteViews remoteViews;
    52.             ComponentName thisWidget;
    53.             AppWidgetManager appWidgetManager;            
    54.  
    55.             public ZachodyWschody(Context context,AppWidgetManager appWidgetManager){
    56.                 this.appWidgetManager = appWidgetManager;
    57.                 remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
    58.                 thisWidget = new ComponentName(context, Zachodnik.class);                
    59.             }
    60.  
    61.             @Override
    62.             public void run(){
    63.  
    64.                 CharSequence w = (CharSequence)Wsch;
    65.                 String Zach = "0000";
    66.                 CharSequence z = (CharSequence)Zach;
    67.                  
    68.                 remoteViews.setTextViewText(R.id.widget_textview, "Wsch

    Advertisement
Loading...

Share This Page