English 中文(简体)
如何在甲型六氯环己烷和甲型六氯环己烷中展示各种 par子的文档?
原标题:How to display various parsed XML files in android?

我正在开发一种应用方法,其中我的一个单元是天气预报。 我正在使用SAX Parser,截至现在,我正在整理XML档案,并获得一个地方的成果。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.saxmain);
    
    ScrollView MyScrollView = new ScrollView(this);
    LinearLayout layout = new LinearLayout(this);
    
    layout.setOrientation(LinearLayout.VERTICAL);
    MyScrollView.addView(layout);
    
    try {
        
        /** Handling XML */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        /** Send URL to parse XML Tags */
        URL sourceUrl = new URL(
                "http://192.168.1.31:81/Udayavani/android/weather/weather.php?city=mumbai");

        /** Create handler to handle XML Tags ( extends DefaultHandler ) */
        MyXMLHandler myXMLHandler = new MyXMLHandler();
        xr.setContentHandler(myXMLHandler);
        xr.parse(new InputSource(sourceUrl.openStream()));
        
    } catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);
    }

 /* Get result from MyXMLHandler TagList Object */
    taglist = MyXMLHandler.sitesList;

      
    
    for (int i = 0; i <26; i++) {
        texts[i] = new TextView(this);
        texts[i].setText(""+i);
        texts[i].setTypeface(kannada);
        layout.addView(texts[i]);
        
        
    }
    /** Set the result text in textview and add it to layout */
        texts[0].setText("Current= "+taglist.getCurrent().get(0));
        texts[1].setText("Temp= "+taglist.getTemp().get(0));
        texts[2].setText("Humidity= "+taglist.getHumidity().get(0));
        texts[3].setText(""+taglist.getWind_condition().get(0));
        texts[4].setText(""+taglist.getIcon().get(0));
       int j=0; 
       int k=5;
        while(k<20){
        texts[k].setText("----------------------------------"); 
        k++;
        texts[k].setText("Day= "+taglist.getDay().get(j));
        k++;
        texts[k].setText("Condition= "+taglist.getCondition().get(j));
        k++;
        texts[k].setText("Low= "+taglist.getLow().get(j));
        k++;
        texts[k].setText("High= "+taglist.getHigh().get(j));
        k++;
        texts[k].setText("Icon= "+taglist.getIcon().get(j));
        k++;
        j++;
        if(j>=5){
            j=0;
               }
             }
    

    /** Set the layout view to display */
    setContentView(MyScrollView);

  }
    }

我向SO提出的问题是,谁会帮助我获得各个城市的平坦Xml档案? 我几乎在所有城市都拥有URL,而且我可以认为,通过在我法典中提到的URL(例如天气.php?city=auckland)的末尾改变城市名称。 我从《名单》开始,我有大约20-30个城市作为名单上的党派储存在《意见》中。 每当我点击特定地点时,我就希望获得该特定城市的平坦XMl档案。

请就此向我提供指导。

增 编

EDITED:

xml contents:

            <?xml version="1.0" encoding="UTF-8"?>
  <weather>
<current_conditions>
    <current>ಹೊಗೆಯಾವೃತ</current>
    <temp>95</temp>
    <humidity>Humidity: ೨೩%</humidity>
    <wind_condition>Wind: ಪೂ at 13 km/h</wind_condition>
    <icon>smoke.gif</icon>
</current_conditions>
<forecast_information>
    <forecast0>
        <day>ಶನಿ.</day>
        <condition>ಬಹುಪಾಲು ಬಿಸಿಲು</condition>
        <low>25</low>
        <high>36</high>
        <icon>mostly_sunny.gif</icon>
    </forecast0>
    <forecast1>
        <day>ರ.</day>
        <condition>ಶುಭ್ರ</condition>
        <low>25</low>
        <high>35</high>
        <icon>sunny.gif</icon>
    </forecast1>
    <forecast2>
        <day>ಸೋ.</day>
        <condition>ಬಹುಪಾಲು ಬಿಸಿಲು</condition>
        <low>25</low>
        <high>36</high>
        <icon>mostly_sunny.gif</icon>
    </forecast2>
    <forecast3>
        <day>ಮಂ.</day>
        <condition>ಬಹುಪಾಲು ಬಿಸಿಲು</condition>
        <low>26</low>
        <high>33</high>
        <icon>mostly_sunny.gif</icon>
    </forecast3>
</forecast_information>
最佳回答

I got the solution.I am declaring an array of places called StateNames[].And from my ListView class I am passing putExtra("id",pos) to the class where I have declared my array,and I am accessing it through the following:

String actualUrl="http://192.168.1.31:81/Udayavani/android/weather/weather.php?city=";     
private String[] StateNames={..,..,..};
//In OnCreate()
    Bundle b = getIntent().getExtras();
    id= b.getInt("id");
    String myURL=actualUrl+StateNames[id];
   try {

        /** Handling XML */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        /** Send URL to parse XML Tags */
        URL sourceUrl = new URL(myURL);

        /** Create handler to handle XML Tags ( extends DefaultHandler ) */
        MyXMLHandler myXMLHandler = new MyXMLHandler();
        xr.setContentHandler(myXMLHandler);
        xr.parse(new InputSource(sourceUrl.openStream()));

    } catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);
    }
问题回答

使用清单而不是浏览。 采用ListItemClick()清单方法,将特定清单项目(ur case中的城市)点击,并将其作为一个参数予以通过(该参数应能将城市u的Xml档案传至村)。 欲了解更多名单:





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签