Guest User

Untitled

a guest
Jun 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.56 KB | None | 0 0
  1. package pcs.andriod.fengxiang.shengxian;
  2.  
  3. import java.io.IOException;
  4. import java.io.StringReader;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7.  
  8. import javax.xml.parsers.DocumentBuilder;
  9. import javax.xml.parsers.DocumentBuilderFactory;
  10. import javax.xml.parsers.ParserConfigurationException;
  11.  
  12. import org.w3c.dom.Document;
  13. import org.w3c.dom.Element;
  14. import org.w3c.dom.NodeList;
  15. import org.xml.sax.InputSource;
  16. import org.xml.sax.SAXException;
  17.  
  18. import android.app.ListActivity;
  19. import android.os.Bundle;
  20. import android.view.View;
  21. import android.widget.AdapterView;
  22. import android.widget.ListAdapter;
  23. import android.widget.ListView;
  24. import android.widget.SimpleAdapter;
  25. import android.widget.Toast;
  26. import android.widget.AdapterView.OnItemClickListener;
  27.  
  28.  
  29. public class showlocation extends ListActivity {
  30.     Document doc = null;
  31.    
  32.     public void onCreate(Bundle savedInstanceState) {
  33.         super.onCreate(savedInstanceState);
  34.         setContentView(R.layout.listplaceholder);
  35.  
  36.         GlobalClass abc = new GlobalClass();
  37.        
  38.         String retrievedvalue = abc.getResponseValue();
  39.        
  40.         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  41.         try {
  42.             DocumentBuilder db = dbf.newDocumentBuilder();
  43.             InputSource is = new InputSource();
  44.             is.setCharacterStream(new StringReader(retrievedvalue));
  45.             doc = db.parse(is);
  46.            
  47.            
  48.             } catch (ParserConfigurationException e) {
  49.                 System.out.println("XML parse error: " + e.getMessage());
  50.  
  51.             } catch (SAXException e) {
  52.                 // TODO Auto-generated catch block
  53.                  System.out.println("Wrong XML file structure: " + e.getMessage());
  54.             } catch (IOException e) {
  55.                 // TODO Auto-generated catch block
  56.                  System.out.println("I/O exeption: " + e.getMessage());
  57.             }
  58.         }
  59.         ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
  60.        
  61.         int numResults = XMLfunctions.numResults(doc);{
  62.            
  63.         if (numResults <= 0)
  64.         {
  65.             Toast.makeText(this,"test",Toast.LENGTH_SHORT).show();
  66.         }
  67.        
  68.         NodeList nodes = doc.getElementsByTagName("FaultDetails");
  69.        
  70.         for (int i = 0 ; i < nodes.getLength(); i++)
  71.         {
  72.             Element e = (Element)nodes.item(i);
  73.             HashMap<String, String> map = new HashMap<String, String>();   
  74.             map.put("FaultNumber",XMLfunctions.getValue(e,"FaultNumber"));
  75.             map.put("Description",XMLfunctions.getValue(e,"Description"));
  76.             map.put("Location",XMLfunctions.getValue(e,"Location"));
  77.             map.put("ReportedBy",XMLfunctions.getValue(e,"ReportedBy"));
  78.             map.put("FaultStatus",XMLfunctions.getValue(e,"FaultStatus"));
  79.             mylist.add(map);
  80.         }
  81.        
  82.         ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.xmlmainmenu,
  83.                 new String[] { "FaultNumber", "Description", "Location", "ReportedBy", "FaultStatus" },
  84.                 new int[] { R.id.item_title, R.id.item_subtitle });
  85.         setListAdapter(adapter);
  86.        
  87.         final ListView lv = getListView();
  88.         lv.setTextFilterEnabled(true); 
  89.         lv.setOnItemClickListener(new OnItemClickListener() {
  90.             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {             
  91.                 @SuppressWarnings("unchecked")
  92.                 HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                  
  93.                 Toast.makeText(showlocation.this, "FaultNumber '" + o.get("FaultNumber") + "' was clicked.", Toast.LENGTH_LONG).show();
  94.             }
  95.         });
  96. }
  97. }
Add Comment
Please, Sign In to add comment