我的代码是这个http://jsfiddle.net/navdeep/7TLDu/
private void parseXML(XmlPullParser parser) throws XmlPullParserException,IOException
{
ArrayList<HashMap<String,String>> items = null;
int eventType = parser.getEventType();
CustomObject currentProduct = null;
HashMap<String, String> item = null;
while (eventType != XmlPullParser.END_DOCUMENT){
String name = null;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
item = new HashMap<String,String>();
break;
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equals("member")){
currentProduct = new CustomObject();
} else if (currentProduct != null){
if (name.equals("name")){
currentProduct.name = parser.nextText();
item.put( "line1", currentProduct.name);
} else if (name.equals("position")){
currentProduct.position = parser.nextText();
item.put( "line2", currentProduct.position);
}
}
Log.i(TAG, "Node parsing");
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("member") && currentProduct != null){
items.add(item);
}
}
eventType = parser.next();
}
Log.i(TAG, "Parsing complete");
sa = new SimpleAdapter(this, items,
android.R.layout.two_line_list_item ,
new String[] { "line1","line2" },
new int[] {android.R.id.text1, android.R.id.text2});
setListAdapter( sa );
// printProducts(items);
Log.i(TAG, "setListAdapter");
}
解析 XML 后,我需要在我的 layout.xml 中的 ListView 中显示数据。我向您展示的代码不会在 ListView 中显示列表。
任何人请帮忙。
谢谢!!