Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pcs.andriod.fengxiang.shengxian;
- import java.io.IOException;
- import java.io.StringReader;
- import java.util.ArrayList;
- import java.util.HashMap;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import javax.xml.parsers.ParserConfigurationException;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.NodeList;
- import org.xml.sax.InputSource;
- import org.xml.sax.SAXException;
- import android.app.ListActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- import android.widget.Toast;
- import android.widget.AdapterView.OnItemClickListener;
- public class showlocation extends ListActivity {
- Document doc = null;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.listplaceholder);
- GlobalClass abc = new GlobalClass();
- String retrievedvalue = abc.getResponseValue();
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- try {
- DocumentBuilder db = dbf.newDocumentBuilder();
- InputSource is = new InputSource();
- is.setCharacterStream(new StringReader(retrievedvalue));
- doc = db.parse(is);
- } catch (ParserConfigurationException e) {
- System.out.println("XML parse error: " + e.getMessage());
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- System.out.println("Wrong XML file structure: " + e.getMessage());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- System.out.println("I/O exeption: " + e.getMessage());
- }
- }
- ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
- int numResults = XMLfunctions.numResults(doc);{
- if (numResults <= 0)
- {
- Toast.makeText(this,"test",Toast.LENGTH_SHORT).show();
- }
- NodeList nodes = doc.getElementsByTagName("FaultDetails");
- for (int i = 0 ; i < nodes.getLength(); i++)
- {
- Element e = (Element)nodes.item(i);
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("FaultNumber",XMLfunctions.getValue(e,"FaultNumber"));
- map.put("Description",XMLfunctions.getValue(e,"Description"));
- map.put("Location",XMLfunctions.getValue(e,"Location"));
- map.put("ReportedBy",XMLfunctions.getValue(e,"ReportedBy"));
- map.put("FaultStatus",XMLfunctions.getValue(e,"FaultStatus"));
- mylist.add(map);
- }
- ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.xmlmainmenu,
- new String[] { "FaultNumber", "Description", "Location", "ReportedBy", "FaultStatus" },
- new int[] { R.id.item_title, R.id.item_subtitle });
- setListAdapter(adapter);
- final ListView lv = getListView();
- lv.setTextFilterEnabled(true);
- lv.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- @SuppressWarnings("unchecked")
- HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
- Toast.makeText(showlocation.this, "FaultNumber '" + o.get("FaultNumber") + "' was clicked.", Toast.LENGTH_LONG).show();
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment