0

I want to display name of continents in a ListView, let us call it listContinents . Upon selecting for example US, I want to display all the States there, let's call it ListStates. Upon selecting a particular state, I want to display all the cities in that state, let us call it ListCity. Upon selecting a city, I want to display some info about that city, let us call it listCityInfo. This is a summary for what I said above.

Continent >> States >> Cities >> Info.

How can I create one XML file containing all the information and read from it? Basically I do not know how to make it. I have the information stored in an html file, so should I convert it to an XML file. Is this the way to go?

How will I read the XML file if it contains all the information. If the XML file contains only the Continents, States, or the Cities I know how to read that, but not when all are there. How do I make it work? I don't want to create more than 500 XML files containing the cities for each state, it would be a waste of time.

Is it possible for someone to illustrate to me how this works using any example or link me to useful site?

I will appreciate it, Thank you!

4

2 に答える 2

0

これが私がそれを行う方法です。

  1. SQlite データベースに情報を保存し、アセット フォルダーに配置します。(ただし、Webサービスに精通している場合は、それを使用することをお勧めします。Androidではxmlが面倒なのでjsonを使用してください)
  2. それを読んで、展開可能な listviewに入力します。
    サンプル例
于 2013-01-12T04:19:42.977 に答える
-1
  File newxmlfile = new File("/data/com.itwine/emergency.xml");

        try{
                newxmlfile.createNewFile();
        }catch(IOException e){
                Log.e("IOException", "exception in createNewFile() method");
        }
        //we have to bind the new file with a FileOutputStream
        FileOutputStream fileos = null;        
        try{
                fileos = new FileOutputStream(newxmlfile);
        }catch(FileNotFoundException e){
                Log.e("FileNotFoundException", "can't create FileOutputStream");
        }
        //we create a XmlSerializer in order to write xml data
        XmlSerializer serializer = Xml.newSerializer();
        try {
                //we set the FileOutputStream as output for the serializer, using UTF-8 encoding
                        serializer.setOutput(fileos, "UTF-8");
                        //Write <?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null)
                        serializer.startDocument(null, Boolean.valueOf(true));
                        //set indentation option
                        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
                        //start a tag called "root"
                        serializer.startTag(null, "root");
                        *//**serializer.startTag(null, "Child1");
                        serializer.endTag(null, "Child1");
                        serializer.startTag(null, "Child2");
                        serializer.attribute(null, "attribute", "value");
                        serializer.endTag(null, "Child2");*//*
                        serializer.startTag(null, "EmailId");
                        serializer.text(txtemailid.getText().toString());
                        serializer.endTag(null,"EmailId");
                        serializer.startTag(null, "PhoneNo");
                        serializer.text(txtphoneno.getText().toString());
                        serializer.endTag(null,"PhoneNo");
                        serializer.endTag(null,"root");
                        serializer.endDocument();
                        //write xml data into the FileOutputStream
                        serializer.flush();
                        //finally we close the file stream
                        fileos.close();
                       Toast.makeText(getApplication(), "xml created",Toast.LENGTH_LONG);
                } catch (Exception e) {
                        Log.e("Exception","error occurred while creating xml file");
                }

はい、方法があります。FileOutputStream を使用して Xmlfile を記述し、XMLserializer を使用して属性とタグを設定できます。例を示しました。

于 2013-01-12T04:14:52.753 に答える