这是我的程序,告诉我如何添加进度条或进度对话框
主要活动
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
LinearLayout layout = new LinearLayout(act.this);
layout.setOrientation(1);
用于从 xml 标签ui textview 和 url 声明中检索数字、名称和成本\
TextView no[];
TextView na[];
TextView c[];
setContentView(layout);
url 在这里声明
URL url = new URL("http://api.androidhive.info/pizza/?format=xml");
我检索数据的 xml 标记
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("item");
no = new TextView[nodeList.getLength()];
na = new TextView[nodeList.getLength()];
c = new TextView[nodeList.getLength()];
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
no[i] = new TextView(act.this);
na[i] = new TextView(act.this);
c[i] = new TextView(act.this);
Element fstElmnt = (Element) node;
NodeList idlist = fstElmnt.getElementsByTagName("id");
Element numelement = (Element) idlist.item(0);
idlist = numelement.getChildNodes();
no[i].setText("ID="+ ((Node) idlist.item(0)).getNodeValue());
NodeList namelist = fstElmnt.getElementsByTagName("name");
Element namelement = (Element) namelist.item(0);
namelist = namelement.getChildNodes();
na[i].setText("pizza name="+ ((Node) namelist.item(0)).getNodeValue());
NodeList costlist = fstElmnt.getElementsByTagName("cost");
Element costlement = (Element) costlist.item(0);
costlist = costlement.getChildNodes();
c[i].setText("cost="+ ((Node) costlist.item(0)).getNodeValue());
layout.addView(no[i]);
layout.addView(na[i]);
layout.addView(c[i]);
}}
catch (Exception e) {
}
}}
程序结束