message error

Put your problem here if it does not fit any of the other categories.

message error

Postby android2 » Sun Oct 25, 2009 5:02 pm

if the field is empty I send the error message where wrong


public class localizza extends Activity {


private EditText latitudine;
private EditText longitudine;
private Button btnlocalizza;
private static ProgressDialog pd;
private Thread trovaerrore;
public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
setContentView(R.layout.localizza);
latitudine = (EditText) findViewById(R.id.widget30_latitudine);
longitudine = (EditText) findViewById(R.id.widget31_longitudine);
btnlocalizza = (Button) findViewById(R.id.mymap2_btn_localizza);

btnlocalizza.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

pd = ProgressDialog.show(localizza.this, "Localizzo", "la tua posizione", true, false);

trovaerrore = new Thread() {
public void run(){

try {
Intent myMap = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("geo:0,0?q=http://www.boole.it/kml/generale.kml");
myMap.setData(uri);
startActivity(Intent.createChooser(myMap, "mymap2"));
Thread.sleep(1500);
} catch (Exception e) {

}
mostraindirizzo.sendEmptyMessage(0);
}
};
trovaerrore.start();

}
});
}

private Handler mostraindirizzo = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();

if (latitudine.getTextSize() == -1) {
Dialog locationError = new AlertDialog.Builder(
localizza.this).setIcon(0).setTitle(
"Errore").setPositiveButton(R.string.ok, null)
.setMessage(
"Input non trovato.")
.create();
locationError.show();

}

}

};
}
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Top

Postby qlimax » Mon Oct 26, 2009 1:07 am

what's your question :?:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby android2 » Mon Oct 26, 2009 10:36 am

do not see the error message!!!!!!
qlimax wrote:what's your question :?:
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Postby qlimax » Mon Oct 26, 2009 11:31 am

you have to use

if(latitudine.length()==0)

to check if the input is zero-length.

getTextSize give you the size of the font.





Ciao :run:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby android2 » Mon Oct 26, 2009 11:57 am

theoretically should block and must return data entry??
qlimax wrote:you have to use

if(latitudine.length()==0)

to check if the input is zero-length.

getTextSize give you the size of the font.





Ciao :run:
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Postby android2 » Mon Oct 26, 2009 12:06 pm

theoretically should block and must return data entry??
qlimax wrote:you have to use

if(latitudine.length()==0)

to check if the input is zero-length.

getTextSize give you the size of the font.





Ciao :run:
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Top

Postby qlimax » Mon Oct 26, 2009 12:12 pm

android2 wrote:theoretically should block and must return data entry??


lol ma che significa :?:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby android2 » Mon Oct 26, 2009 12:57 pm

no ho risolto !!!!
visto che sei italiano ti volevo chiedere se sai fare il parsing e il filtering in kml grazie collega ciao
qlimax wrote:
android2 wrote:theoretically should block and must return data entry??


lol ma che significa :?:
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Postby qlimax » Mon Oct 26, 2009 1:27 pm

non ho mai provato a fare il parsing di un kml.

ma probabilmente non è molto differente da quello che si fa con i classici xml, anzi sicuramente è uguale.

android usa il saxparser della libreria javax, quello usato anche per le applicazioni desktop normali.

qui un esempio

parsing_xml_from_the_net_-_using_the_saxparser-t353.html



CIAO

:run:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby qlimax » Mon Oct 26, 2009 1:31 pm

a, comunque sono svizzero.... :)
http://it.wikipedia.org/wiki/Canton_Ticino

ciao ;D
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby android2 » Mon Oct 26, 2009 3:57 pm

io dovrei mettere i risultati della ricerca o meglio del filtering kml in array list potresti aiutarmi ??
qlimax wrote:a, comunque sono svizzero.... :)
http://it.wikipedia.org/wiki/Canton_Ticino

ciao ;D
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Postby qlimax » Mon Oct 26, 2009 7:25 pm

ok, ho preso l esempio e l' ho modificato un attimo.

Mettiamo ad esempio di analizzare il kml seguente:

http://www.boole.it/kml/generale.kml

e voler archiviare in un arraylist alcuni dati riguardanti i placemark.

nome
indirizzo
coordinate

ecco un estratto del kml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <Placemark>
  2.                 <name>Cinema Teatro Royal Di Diana Nicoletta Irma</name>
  3.                 <address>Corso Italia, 112&lt;br/&gt;70123 Bari, Bari (Puglia)</address>
  4.                 <Snippet maxLines="2"><![CDATA[Corso Italia, 112, 70123 Bari, Bari (Puglia)<br/>080 5211668]]></Snippet>
  5.                 <styleUrl>#msn_electronics0</styleUrl>
  6.                 <ExtendedData>
  7.                         <Data name="balloon_text">
  8.                                 <value><![CDATA[<table width ="200"><tr><td colspan="2"><font size="+1"><b><a href="http://maps.google.it/maps?q=cinema&near=piazza+del+ferrarese+bari&ie=UTF8&v=2.2&cv=5.1.3509.4636&hl=it&latlng=918349370681778073&ei=EUXPSp--OsjesgbjwMjeCQ&cd=5">$[name]</a></b></font><br/><font color="#808080"></font></td></tr><tr><td>Corso Italia, 112<br/>70123 Bari, Bari (Puglia)<br/>080 5211668<br/><a href="http://www.mymovies.it/cinema/bari/alberobello/" style="color:#008000">mymovies.it</a></td></tr></table><br/><br/>  $[geDirections]]]></value>
  9.                         </Data>
  10.                         <Data name="contents">
  11.                                 <value>Cinema Teatro Royal Di Diana Nicoletta Irma+Cinema+Cinema+Cinema+Tempo libero+Movie Theaters+Kinos+Cines+Cinémas+Movie Theaters</value>
  12.                         </Data>
  13.                         <Data name="city">
  14.                                 <value>Bari</value>
  15.                         </Data>
  16.                 </ExtendedData>
  17.                 <Point>
  18.                         <coordinates>16.864924,41.118314,0</coordinates>
  19.                 </Point>
  20.         </Placemark>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



:arrow: per prima cosa crei una struttura dati per i placemark

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. public class PlacemarkDataSet {
  4. public String name;
  5. public String address;
  6. public String coordinates;
  7.  
  8. public String toString(){
  9.         return name+" "+address+" "+coordinates;
  10. }
  11. }
Parsed in 0.029 seconds, using GeSHi 1.0.8.4



:arrow: poi crei un attività dove inizializzi il parser, lanci il parsing e ti fai ritornare i dati d' interesse
(Puoi anche aggiungere il codice ad una tua attività esistente)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. import java.net.URL;
  4. import java.util.ArrayList;
  5.  
  6. import javax.xml.parsers.SAXParser;
  7. import javax.xml.parsers.SAXParserFactory;
  8.  
  9. import org.xml.sax.InputSource;
  10. import org.xml.sax.XMLReader;
  11.  
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14.  
  15. import android.util.Log;
  16. import android.widget.ScrollView;
  17. import android.widget.TextView;
  18.  
  19. public class Parser extends Activity {
  20.      
  21.      
  22.  
  23.      /** Called when the activity is first created. */
  24.      @Override
  25.      public void onCreate(Bundle icicle) {
  26.           super.onCreate(icicle);
  27.  
  28.           /* Create a new TextView to display the parsingresult later. */
  29.           ScrollView sv=new ScrollView(this);
  30.           TextView tv = new TextView(this);
  31.           sv.addView(tv);
  32.           this.setContentView(sv);
  33.           try {
  34.                /* Create a URL we want to load some xml-data from. */
  35.                URL url = new URL("http://www.xxxxx.net/kml/file.kml");
  36.  
  37.                /* Get a SAXParser from the SAXPArserFactory. */
  38.                SAXParserFactory spf = SAXParserFactory.newInstance();
  39.                SAXParser sp = spf.newSAXParser();
  40.  
  41.                /* Get the XMLReader of the SAXParser we created. */
  42.                XMLReader xr = sp.getXMLReader();
  43.                /* Create a new ContentHandler and apply it to the XML-Reader*/
  44.                ExampleHandler myExampleHandler = new ExampleHandler();
  45.                xr.setContentHandler(myExampleHandler);
  46.                
  47.                /* Parse the xml-data from our URL. */
  48.                xr.parse(new InputSource(url.openStream()));
  49.                /* Parsing has finished. */
  50.  
  51.                /* Our ExampleHandler now provides the parsed data to us. */
  52.                ArrayList<PlacemarkDataSet> parsedExampleDataSet =myExampleHandler.getParsedData();
  53.                        
  54.                for(int i=0;i<parsedExampleDataSet.size();i++)
  55.                tv.append(parsedExampleDataSet.get(i).toString()+"nn");
  56.                
  57.           } catch (Exception e) {
  58.                /* Display any Error to the GUI. */
  59.                tv.setText("Error: " + e.getMessage());
  60.                
  61.                Log.e("", e.toString());
  62.                
  63.           }
  64.           /* Display the TextView. */
  65.          
  66.      }
  67. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


:arrow: in fine crei il modo in cui il parser agisce sul tuo xml (kml)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.xml.sax.Attributes;
  6. import org.xml.sax.SAXException;
  7. import org.xml.sax.helpers.DefaultHandler;
  8.  
  9.  
  10. public class ExampleHandler extends DefaultHandler{
  11.  
  12.      // ===========================================================
  13.      // Fields
  14.      // ===========================================================
  15.      
  16.      private boolean in_placemark = false;
  17.      private boolean in_name = false;
  18.      private boolean in_address = false;
  19.      private boolean in_point=false;
  20.      private boolean in_coordinates=false;
  21.      
  22.      private ArrayList<PlacemarkDataSet> placemarkArrayList;
  23.      
  24.      private PlacemarkDataSet tempPlacemark;
  25.  
  26.      // ===========================================================
  27.      // Getter & Setter
  28.      // ===========================================================
  29.  
  30.      public ArrayList<PlacemarkDataSet> getParsedData() {
  31.           return this.placemarkArrayList;
  32.      }
  33.  
  34.      // ===========================================================
  35.      // Methods
  36.      // ===========================================================
  37.      @Override
  38.      public void startDocument() throws SAXException {
  39.           this.placemarkArrayList = new ArrayList<PlacemarkDataSet>();
  40.      }
  41.  
  42.      @Override
  43.      public void endDocument() throws SAXException {
  44.           // Nothing to do
  45.      }
  46.  
  47.    
  48.      @Override
  49.      public void startElement(String namespaceURI, String localName,
  50.                String qName, Attributes atts) throws SAXException {
  51.           if (localName.equals("Placemark")) {
  52.                this.in_placemark = true;
  53.                
  54.                tempPlacemark=new PlacemarkDataSet();
  55.                
  56.           }else if (localName.equals("name")) {
  57.                this.in_name = true;
  58.           }else if (localName.equals("address")) {
  59.                this.in_address = true;
  60.           }else if (localName.equals("Point")) {
  61.                this.in_point=true;
  62.           }else if (localName.equals("coordinates")) {
  63.               this.in_coordinates=true;
  64.           }
  65.      }
  66.      
  67.      /** Gets be called on closing tags like:
  68.       * </tag> */
  69.      @Override
  70.      public void endElement(String namespaceURI, String localName, String qName)
  71.                throws SAXException {
  72.           if (localName.equals("Placemark")) {
  73.               this.in_placemark = false;
  74.              
  75.               placemarkArrayList.add(tempPlacemark);
  76.              
  77.          }else if (localName.equals("name")) {
  78.               this.in_name = false;
  79.          }else if (localName.equals("address")) {
  80.               this.in_address = false;
  81.          }else if (localName.equals("Point")) {
  82.               this.in_point=false;
  83.          }else if (localName.equals("coordinates")) {
  84.              this.in_coordinates=false;
  85.          }
  86.      }
  87.      
  88.      /** Gets be called on the following structure:
  89.       * <tag>characters</tag> */
  90.      @Override
  91.     public void characters(char ch[], int start, int length) {
  92.           if(this.in_placemark&&this.in_name){
  93.           tempPlacemark.name=new String(ch, start, length);
  94.           }else if(this.in_placemark&&this.in_address){
  95.                   tempPlacemark.address=new String(ch, start, length);
  96.           }else if (this.in_placemark&&this.in_point&&this.in_coordinates){
  97.                   tempPlacemark.coordinates=new String(ch, start, length);
  98.           }
  99.     }
  100. }
Parsed in 0.048 seconds, using GeSHi 1.0.8.4



risultato

Image


se hai domande chiedi pure :)

Saluti :run:
Last edited by qlimax on Tue Oct 27, 2009 1:50 am, edited 1 time in total.
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby android2 » Mon Oct 26, 2009 9:12 pm

mi dai il tuo contatto msn o la tua mail
qlimax wrote:ok, ho preso l esempio e l' ho modificato un attimo.

Mettiamo ad esempio di analizzare il kml seguente:



e voler archiviare in un arraylist alcuni dati riguardanti i placemark.

nome
indirizzo
coordinate

ecco un estratto del kml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <Placemark>
  2.                 <name>Cinema Teatro Royal Di Diana Nicoletta Irma</name>
  3.                 <address>Corso Italia, 112&lt;br/&gt;70123 Bari, Bari (Puglia)</address>
  4.                 <Snippet maxLines="2"><![CDATA[Corso Italia, 112, 70123 Bari, Bari (Puglia)<br/>080 5211668]]></Snippet>
  5.                 <styleUrl>#msn_electronics0</styleUrl>
  6.                 <ExtendedData>
  7.                         <Data name="balloon_text">
  8.                                 <value><![CDATA[<table width ="200"><tr><td colspan="2"><font size="+1"><b><a href="http://maps.google.it/maps?q=cinema&near=piazza+del+ferrarese+bari&ie=UTF8&v=2.2&cv=5.1.3509.4636&hl=it&latlng=918349370681778073&ei=EUXPSp--OsjesgbjwMjeCQ&cd=5">$[name]</a></b></font><br/><font color="#808080"></font></td></tr><tr><td>Corso Italia, 112<br/>70123 Bari, Bari (Puglia)<br/>080 5211668<br/><a href="http://www.mymovies.it/cinema/bari/alberobello/" style="color:#008000">mymovies.it</a></td></tr></table><br/><br/>  $[geDirections]]]></value>
  9.                         </Data>
  10.                         <Data name="contents">
  11.                                 <value>Cinema Teatro Royal Di Diana Nicoletta Irma+Cinema+Cinema+Cinema+Tempo libero+Movie Theaters+Kinos+Cines+Cinémas+Movie Theaters</value>
  12.                         </Data>
  13.                         <Data name="city">
  14.                                 <value>Bari</value>
  15.                         </Data>
  16.                 </ExtendedData>
  17.                 <Point>
  18.                         <coordinates>16.864924,41.118314,0</coordinates>
  19.                 </Point>
  20.         </Placemark>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



:arrow: per prima cosa crei una struttura dati per i placemark

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. public class PlacemarkDataSet {
  4. public String name;
  5. public String address;
  6. public String coordinates;
  7.  
  8. public String toString(){
  9.         return name+" "+address+" "+coordinates;
  10. }
  11. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



:arrow: poi crei un attività dove inizializzi il parser, lanci il parsing e ti fai ritornare i dati d' interesse
(Puoi anche aggiungere il codice ad una tua attività esistente)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. import java.net.URL;
  4. import java.util.ArrayList;
  5.  
  6. import javax.xml.parsers.SAXParser;
  7. import javax.xml.parsers.SAXParserFactory;
  8.  
  9. import org.xml.sax.InputSource;
  10. import org.xml.sax.XMLReader;
  11.  
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14.  
  15. import android.util.Log;
  16. import android.widget.ScrollView;
  17. import android.widget.TextView;
  18.  
  19. public class Parser extends Activity {
  20.      
  21.      
  22.  
  23.      /** Called when the activity is first created. */
  24.      @Override
  25.      public void onCreate(Bundle icicle) {
  26.           super.onCreate(icicle);
  27.  
  28.           /* Create a new TextView to display the parsingresult later. */
  29.           ScrollView sv=new ScrollView(this);
  30.           TextView tv = new TextView(this);
  31.           sv.addView(tv);
  32.           this.setContentView(sv);
  33.           try {
  34.                /* Create a URL we want to load some xml-data from. */
  35.                URL url = new URL("http://www.xxxx.kml");
  36.  
  37.                /* Get a SAXParser from the SAXPArserFactory. */
  38.                SAXParserFactory spf = SAXParserFactory.newInstance();
  39.                SAXParser sp = spf.newSAXParser();
  40.  
  41.                /* Get the XMLReader of the SAXParser we created. */
  42.                XMLReader xr = sp.getXMLReader();
  43.                /* Create a new ContentHandler and apply it to the XML-Reader*/
  44.                ExampleHandler myExampleHandler = new ExampleHandler();
  45.                xr.setContentHandler(myExampleHandler);
  46.                
  47.                /* Parse the xml-data from our URL. */
  48.                xr.parse(new InputSource(url.openStream()));
  49.                /* Parsing has finished. */
  50.  
  51.                /* Our ExampleHandler now provides the parsed data to us. */
  52.                ArrayList<PlacemarkDataSet> parsedExampleDataSet =myExampleHandler.getParsedData();
  53.                        
  54.                for(int i=0;i<parsedExampleDataSet.size();i++)
  55.                tv.append(parsedExampleDataSet.get(i).toString()+"nn");
  56.                
  57.           } catch (Exception e) {
  58.                /* Display any Error to the GUI. */
  59.                tv.setText("Error: " + e.getMessage());
  60.                
  61.                Log.e("", e.toString());
  62.                
  63.           }
  64.           /* Display the TextView. */
  65.          
  66.      }
  67. }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


:arrow: in fine crei il modo in cui il parser agisce sul tuo xml (kml)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.xml.sax.Attributes;
  6. import org.xml.sax.SAXException;
  7. import org.xml.sax.helpers.DefaultHandler;
  8.  
  9.  
  10. public class ExampleHandler extends DefaultHandler{
  11.  
  12.      // ===========================================================
  13.      // Fields
  14.      // ===========================================================
  15.      
  16.      private boolean in_placemark = false;
  17.      private boolean in_name = false;
  18.      private boolean in_address = false;
  19.      private boolean in_point=false;
  20.      private boolean in_coordinates=false;
  21.      
  22.      private ArrayList<PlacemarkDataSet> placemarkArrayList;
  23.      
  24.      private PlacemarkDataSet tempPlacemark;
  25.  
  26.      // ===========================================================
  27.      // Getter & Setter
  28.      // ===========================================================
  29.  
  30.      public ArrayList<PlacemarkDataSet> getParsedData() {
  31.           return this.placemarkArrayList;
  32.      }
  33.  
  34.      // ===========================================================
  35.      // Methods
  36.      // ===========================================================
  37.      @Override
  38.      public void startDocument() throws SAXException {
  39.           this.placemarkArrayList = new ArrayList<PlacemarkDataSet>();
  40.      }
  41.  
  42.      @Override
  43.      public void endDocument() throws SAXException {
  44.           // Nothing to do
  45.      }
  46.  
  47.    
  48.      @Override
  49.      public void startElement(String namespaceURI, String localName,
  50.                String qName, Attributes atts) throws SAXException {
  51.           if (localName.equals("Placemark")) {
  52.                this.in_placemark = true;
  53.                
  54.                tempPlacemark=new PlacemarkDataSet();
  55.                
  56.           }else if (localName.equals("name")) {
  57.                this.in_name = true;
  58.           }else if (localName.equals("address")) {
  59.                this.in_address = true;
  60.           }else if (localName.equals("Point")) {
  61.                this.in_point=true;
  62.           }else if (localName.equals("coordinates")) {
  63.               this.in_coordinates=true;
  64.           }
  65.      }
  66.      
  67.      /** Gets be called on closing tags like:
  68.       * </tag> */
  69.      @Override
  70.      public void endElement(String namespaceURI, String localName, String qName)
  71.                throws SAXException {
  72.           if (localName.equals("Placemark")) {
  73.               this.in_placemark = false;
  74.              
  75.               placemarkArrayList.add(tempPlacemark);
  76.              
  77.          }else if (localName.equals("name")) {
  78.               this.in_name = false;
  79.          }else if (localName.equals("address")) {
  80.               this.in_address = false;
  81.          }else if (localName.equals("Point")) {
  82.               this.in_point=false;
  83.          }else if (localName.equals("coordinates")) {
  84.              this.in_coordinates=false;
  85.          }
  86.      }
  87.      
  88.      /** Gets be called on the following structure:
  89.       * <tag>characters</tag> */
  90.      @Override
  91.     public void characters(char ch[], int start, int length) {
  92.           if(this.in_placemark&&this.in_name){
  93.           tempPlacemark.name=new String(ch, start, length);
  94.           }else if(this.in_placemark&&this.in_address){
  95.                   tempPlacemark.address=new String(ch, start, length);
  96.           }else if (this.in_placemark&&this.in_point&&this.in_coordinates){
  97.                   tempPlacemark.coordinates=new String(ch, start, length);
  98.           }
  99.     }
  100. }
Parsed in 0.050 seconds, using GeSHi 1.0.8.4



risultato

Image


se hai domande chiedi pure :)

Saluti :run:
Last edited by android2 on Tue Oct 27, 2009 2:34 pm, edited 2 times in total.
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Postby android2 » Tue Oct 27, 2009 11:44 am

io devo fare un filtering in modo che quando clicco sulla listview bar mi mostri sulla mappa solo i bar
android2 wrote:mi dai il tuo contatto msn o la tua mail
qlimax wrote:ok, ho preso l esempio e l' ho modificato un attimo.

Mettiamo ad esempio di analizzare il kml seguente:

http://www.xxxxe.kml

e voler archiviare in un arraylist alcuni dati riguardanti i placemark.

nome
indirizzo
coordinate

ecco un estratto del kml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <Placemark>
  2.                 <name>Cinema Teatro Royal Di Diana Nicoletta Irma</name>
  3.                 <address>Corso Italia, 112&lt;br/&gt;70123 Bari, Bari (Puglia)</address>
  4.                 <Snippet maxLines="2"><![CDATA[Corso Italia, 112, 70123 Bari, Bari (Puglia)<br/>080 5211668]]></Snippet>
  5.                 <styleUrl>#msn_electronics0</styleUrl>
  6.                 <ExtendedData>
  7.                         <Data name="balloon_text">
  8.                                 <value><![CDATA[<table width ="200"><tr><td colspan="2"><font size="+1"><b><a href="http://maps.google.it/maps?q=cinema&near=piazza+del+ferrarese+bari&ie=UTF8&v=2.2&cv=5.1.3509.4636&hl=it&latlng=918349370681778073&ei=EUXPSp--OsjesgbjwMjeCQ&cd=5">$[name]</a></b></font><br/><font color="#808080"></font></td></tr><tr><td>Corso Italia, 112<br/>70123 Bari, Bari (Puglia)<br/>080 5211668<br/><a href="http://www.mymovies.it/cinema/bari/alberobello/" style="color:#008000">mymovies.it</a></td></tr></table><br/><br/>  $[geDirections]]]></value>
  9.                         </Data>
  10.                         <Data name="contents">
  11.                                 <value>Cinema Teatro Royal Di Diana Nicoletta Irma+Cinema+Cinema+Cinema+Tempo libero+Movie Theaters+Kinos+Cines+Cinémas+Movie Theaters</value>
  12.                         </Data>
  13.                         <Data name="city">
  14.                                 <value>Bari</value>
  15.                         </Data>
  16.                 </ExtendedData>
  17.                 <Point>
  18.                         <coordinates>16.864924,41.118314,0</coordinates>
  19.                 </Point>
  20.         </Placemark>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



:arrow: per prima cosa crei una struttura dati per i placemark

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. public class PlacemarkDataSet {
  4. public String name;
  5. public String address;
  6. public String coordinates;
  7.  
  8. public String toString(){
  9.         return name+" "+address+" "+coordinates;
  10. }
  11. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



:arrow: poi crei un attività dove inizializzi il parser, lanci il parsing e ti fai ritornare i dati d' interesse
(Puoi anche aggiungere il codice ad una tua attività esistente)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. import java.net.URL;
  4. import java.util.ArrayList;
  5.  
  6. import javax.xml.parsers.SAXParser;
  7. import javax.xml.parsers.SAXParserFactory;
  8.  
  9. import org.xml.sax.InputSource;
  10. import org.xml.sax.XMLReader;
  11.  
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14.  
  15. import android.util.Log;
  16. import android.widget.ScrollView;
  17. import android.widget.TextView;
  18.  
  19. public class Parser extends Activity {
  20.      
  21.      
  22.  
  23.      /** Called when the activity is first created. */
  24.      @Override
  25.      public void onCreate(Bundle icicle) {
  26.           super.onCreate(icicle);
  27.  
  28.           /* Create a new TextView to display the parsingresult later. */
  29.           ScrollView sv=new ScrollView(this);
  30.           TextView tv = new TextView(this);
  31.           sv.addView(tv);
  32.           this.setContentView(sv);
  33.           try {
  34.                /* Create a URL we want to load some xml-data from. */
  35.                URL url = new URL("http://www.xxxx.kml");
  36.  
  37.                /* Get a SAXParser from the SAXPArserFactory. */
  38.                SAXParserFactory spf = SAXParserFactory.newInstance();
  39.                SAXParser sp = spf.newSAXParser();
  40.  
  41.                /* Get the XMLReader of the SAXParser we created. */
  42.                XMLReader xr = sp.getXMLReader();
  43.                /* Create a new ContentHandler and apply it to the XML-Reader*/
  44.                ExampleHandler myExampleHandler = new ExampleHandler();
  45.                xr.setContentHandler(myExampleHandler);
  46.                
  47.                /* Parse the xml-data from our URL. */
  48.                xr.parse(new InputSource(url.openStream()));
  49.                /* Parsing has finished. */
  50.  
  51.                /* Our ExampleHandler now provides the parsed data to us. */
  52.                ArrayList<PlacemarkDataSet> parsedExampleDataSet =myExampleHandler.getParsedData();
  53.                        
  54.                for(int i=0;i<parsedExampleDataSet.size();i++)
  55.                tv.append(parsedExampleDataSet.get(i).toString()+"nn");
  56.                
  57.           } catch (Exception e) {
  58.                /* Display any Error to the GUI. */
  59.                tv.setText("Error: " + e.getMessage());
  60.                
  61.                Log.e("", e.toString());
  62.                
  63.           }
  64.           /* Display the TextView. */
  65.          
  66.      }
  67. }
Parsed in 0.046 seconds, using GeSHi 1.0.8.4


:arrow: in fine crei il modo in cui il parser agisce sul tuo xml (kml)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package ch.egsolutions.parsing;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.xml.sax.Attributes;
  6. import org.xml.sax.SAXException;
  7. import org.xml.sax.helpers.DefaultHandler;
  8.  
  9.  
  10. public class ExampleHandler extends DefaultHandler{
  11.  
  12.      // ===========================================================
  13.      // Fields
  14.      // ===========================================================
  15.      
  16.      private boolean in_placemark = false;
  17.      private boolean in_name = false;
  18.      private boolean in_address = false;
  19.      private boolean in_point=false;
  20.      private boolean in_coordinates=false;
  21.      
  22.      private ArrayList<PlacemarkDataSet> placemarkArrayList;
  23.      
  24.      private PlacemarkDataSet tempPlacemark;
  25.  
  26.      // ===========================================================
  27.      // Getter & Setter
  28.      // ===========================================================
  29.  
  30.      public ArrayList<PlacemarkDataSet> getParsedData() {
  31.           return this.placemarkArrayList;
  32.      }
  33.  
  34.      // ===========================================================
  35.      // Methods
  36.      // ===========================================================
  37.      @Override
  38.      public void startDocument() throws SAXException {
  39.           this.placemarkArrayList = new ArrayList<PlacemarkDataSet>();
  40.      }
  41.  
  42.      @Override
  43.      public void endDocument() throws SAXException {
  44.           // Nothing to do
  45.      }
  46.  
  47.    
  48.      @Override
  49.      public void startElement(String namespaceURI, String localName,
  50.                String qName, Attributes atts) throws SAXException {
  51.           if (localName.equals("Placemark")) {
  52.                this.in_placemark = true;
  53.                
  54.                tempPlacemark=new PlacemarkDataSet();
  55.                
  56.           }else if (localName.equals("name")) {
  57.                this.in_name = true;
  58.           }else if (localName.equals("address")) {
  59.                this.in_address = true;
  60.           }else if (localName.equals("Point")) {
  61.                this.in_point=true;
  62.           }else if (localName.equals("coordinates")) {
  63.               this.in_coordinates=true;
  64.           }
  65.      }
  66.      
  67.      /** Gets be called on closing tags like:
  68.       * </tag> */
  69.      @Override
  70.      public void endElement(String namespaceURI, String localName, String qName)
  71.                throws SAXException {
  72.           if (localName.equals("Placemark")) {
  73.               this.in_placemark = false;
  74.              
  75.               placemarkArrayList.add(tempPlacemark);
  76.              
  77.          }else if (localName.equals("name")) {
  78.               this.in_name = false;
  79.          }else if (localName.equals("address")) {
  80.               this.in_address = false;
  81.          }else if (localName.equals("Point")) {
  82.               this.in_point=false;
  83.          }else if (localName.equals("coordinates")) {
  84.              this.in_coordinates=false;
  85.          }
  86.      }
  87.      
  88.      /** Gets be called on the following structure:
  89.       * <tag>characters</tag> */
  90.      @Override
  91.     public void characters(char ch[], int start, int length) {
  92.           if(this.in_placemark&&this.in_name){
  93.           tempPlacemark.name=new String(ch, start, length);
  94.           }else if(this.in_placemark&&this.in_address){
  95.                   tempPlacemark.address=new String(ch, start, length);
  96.           }else if (this.in_placemark&&this.in_point&&this.in_coordinates){
  97.                   tempPlacemark.coordinates=new String(ch, start, length);
  98.           }
  99.     }
  100. }
Parsed in 0.050 seconds, using GeSHi 1.0.8.4



risultato

Image


se hai domande chiedi pure :)

Saluti :run:
Last edited by android2 on Tue Oct 27, 2009 2:36 pm, edited 2 times in total.
android2
Developer
Developer
 
Posts: 48
Joined: Sun Oct 04, 2009 8:34 pm

Postby qlimax » Tue Oct 27, 2009 2:17 pm

non ci sentivamo x email? penso che su questo forum la lingua ufficiale non sia l'italiano :P non vorrei che qualcuno iniziasse a stressare per questo...

Comunque, ti posso aiutare. ma dovresti essere più preciso:

"quando clicco sulla listview bar" cosa intendi precisamente ?
con il termine "filtering" penso che intendi parsing (?)

dammi un quadro completo dell'applicazione che vuoi sviluppare:
-cosa vuoi raggiungere.
-dove sei arrivato fin ora.


ps: nei tuoi post, quando mi quoti c'è sempre il nome del sito.... dovresti modificare i tuoi post se vuoi che il sito non si veda...
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 9 guests