I am pretty new to android studio and have a question that I can't seem to solve. I am parsing some XML from a website using a for loop to get each element. My question is how do I pause it on the first iteration through the for loop, so that it won't continue to the next until this button is clicked?
Here is my for loop:
try {
URL url = new URL("http://www.website.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("patient_order");
/** Assign textview array length by arraylist size */
patientName = new TextView[nodeList.getLength()];
patientID = new TextView[nodeList.getLength()];
medicine = new TextView[nodeList.getLength()];
dosage = new TextView[nodeList.getLength()];
refillsRemaining = new TextView[nodeList.getLength()];
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
patientName[i] = new TextView(this);
patientID[i] = new TextView(this);
medicine[i] = new TextView(this);
dosage[i] = new TextView(this);
refillsRemaining[i] = new TextView(this);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("patientName");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
patientName[i].setText("Patient: "
+ ((Node) nameList.item(0)).getNodeValue());
NodeList websiteList = fstElmnt.getElementsByTagName("patientID");
Element websiteElement = (Element) websiteList.item(0);
websiteList = websiteElement.getChildNodes();
patientID[i].setText("ID: "
+ ((Node) websiteList.item(0)).getNodeValue());
NodeList medicineList = fstElmnt.getElementsByTagName("medicine");
Element medicineElement = (Element) medicineList.item(0);
medicineList = medicineElement.getChildNodes();
medicine[i].setText("RX: "
+ ((Node) medicineList.item(0)).getNodeValue());
NodeList dosageList = fstElmnt.getElementsByTagName("dosage");
Element dosageElement = (Element) dosageList.item(0);
dosageList = dosageElement.getChildNodes();
dosage[i].setText("Dosage: "
+ ((Node) dosageList.item(0)).getNodeValue());
NodeList refillsList = fstElmnt.getElementsByTagName("refillsRemaining");
Element refillsElement = (Element) refillsList.item(0);
refillsList = refillsElement.getChildNodes();
refillsRemaining[i].setText("Remaining: "
+ ((Node) refillsList.item(0)).getNodeValue());
layout.addView(patientName[i]);
layout.addView(patientID[i]);
layout.addView(medicine[i]);
layout.addView(dosage[i]);
layout.addView(refillsRemaining[i]);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
//What is going to happen to make the for loop continue
}
});
}//end for
} //end try