我正在编写一个简单地解析XML的代码;但是,在简单的if-else if结构中,应用程序仅在我打开{
之后才执行中间语句private void processParsingUsuario(XmlPullParser parser) throws IOException, XmlPullParserException{
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
String eltName = null;
if(eventType == XmlPullParser.START_DOCUMENT) {
Log.i("Info","inicia el xml");
} else if(eventType == XmlPullParser.START_TAG) {
eltName = parser.getName();
Log.i("Info","inicia el tag " + eltName);
if("usu_id".equals(eltName)) {
Log.i("Info","usu id = " + parser.nextText());
usuario.usu_id = parser.nextText();
} else if("usu_nombre".equals(eltName)) {
Log.i("Info","usu nombre = " + parser.nextText());
} else if("usu_nombrecorto".equals(eltName)) {
welcomeText.setText("Hola " + parser.nextText());
Log.i("Info","usu nombre = " + parser.nextText());
}
}
eventType = parser.next();
}
}
对于最后一个“ else if”,它应该同时执行setText和Log,但是,它仅执行setText。 如果我切换它们(如果我先放置日志,然后再放置setText,那么它只会做日志。