首页 新闻 会员 周边

各位编程爱好者帮忙看下下面的代码?

0
悬赏园豆:100 [已解决问题] 解决于 2012-07-30 14:50

public class Test04Activity extends ListActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
    
  这里应该如何写代码显示下面解析的xml文件返回的list中的内容?
    
}
/**
 * Dom 解析
 *  
 *
 */
public class DomParse
{
  
  /**
  * 输入流
  */
  public InputStream is = null;
  /**
  * 用户数组
  */
  public List<English> list = null;
  
  /**
  * 构造,给2个属性赋值
  *   
  */
  public DomParse(InputStream is)
  {
  this.is = is;
  list = new ArrayList<English>();
  }
  
  /**
  * 解析输入流,并返回用户数组
  * @return List<English>
  */
  public List<English> readXml()
  {
  //生成工厂,
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  try
  {
  //获取DocumentBuilder
  DocumentBuilder db = dbf.newDocumentBuilder();
  try
  {
  //获得Document
  Document doc = db.parse(is);
  //获取根节点
  Element root = doc.getDocumentElement();
  //获取节点
  NodeList node = root.getElementsByTagName("English");
  //获取子节点,并取得text进行赋值
  for (int i = 0; i < node.getLength(); i++)
  {
  English e = new English();
  Element English = (Element) node.item(i);
  NodeList childnode = English.getChildNodes();
  for (int j = 0; j < childnode.getLength(); j++)
  {
  Node node1 = childnode.item(j);
  //判断是否为元素节点
  if (node1.getNodeType() == Node.ELEMENT_NODE)
  {
  Element child = (Element) node1;
  
  if ("id".equals(child.getNodeName()))
  {
  e.setId(child.getFirstChild().getNodeValue());
  
  }
  else if ("text".equals(child.getNodeName()))
  {
  e.setText(child.getFirstChild().getNodeValue());
  }
  }
  }
  list.add(e);
  
  }
  is.close();
  }
  
  catch (SAXException e)
  {
  e.printStackTrace();
  }
  catch (IOException e)
  {
  e.printStackTrace();
  }
  }
  catch (ParserConfigurationException e)
  {
  e.printStackTrace();
  }
  //返回对象
  return list;
  }
}}

a67065的主页 a67065 | 初学一级 | 园豆:112
提问于:2012-05-23 11:02
< >
分享
最佳答案
0

用ListView控件就可以显示吧:

android ListView详解

收获园豆:100
artwl | 专家六级 |园豆:16736 | 2012-05-23 11:38

不知道怎么将list对象显示?可以具体点吗?谢谢!

a67065 | 园豆:112 (初学一级) | 2012-05-23 11:42

解决了,用listview可以解决,谢谢

a67065 | 园豆:112 (初学一级) | 2012-05-29 09:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册