【发布时间】:2012-11-09 10:10:01
【问题描述】:
在我的应用程序中,我正在解析 XML 中的数据。并将它们映射到哈希映射中,最后设置为“ArrayList”。
下面是我的代码:
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
TaplistingParser parser = new TaplistingParser();
String xml= parser.getXmlFromUrl(URL);
Document doc=parser.getDomElement(xml);
// System.out.println("sssss="+doc);
NodeList nl=doc.getElementsByTagName("article");
final String[] url= new String[nl.getLength()];
for(int i=0; i < nl.getLength(); i++ )
{
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
map.put("Title", parser.getValue(e, "title")); -------->
map.put("Date", parser.getValue(e, "create_date")); -------->Here is the array
url[i]=parser.getValue(e, "url");
// map.put("URL", parser.getValue(e, "url"));
menuItems.add(map);
// System.out.println("items="+menuItems);
}
// System.out.println("items="+menuItems);
ListView l1= (ListView)findViewById(R.id.list);
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.homelistrow,
new String[] {"Title"}, new int[]
{
R.id.name_label});
l1.setAdapter(adapter);
现在在上面的代码中我有日期和标题。
我必须像这样显示列表:
2012-11-09
qqqqqqqqqqqqqqqq
------------------
2012-11-09
ddddddddddddddd
-----------------
如何在列表中的 2 个文本视图中显示 2 个数组。我是新手,请帮助我。提前致谢。
【问题讨论】:
-
你需要什么 2 阵列?只需创建一些具有两个属性的类 - 标题、日期,然后创建 List
,将 XML 中的数据解析到该对象,并使用 List 创建一些适配器的子类。 -
谢谢骗子..但是在我上面的代码中..你能说我必须做什么来完成这个..
-
您必须有一个扩展基本适配器的自定义适配器.....然后将该自定义适配器用于您的列表视图..它不应该是一个简单的列表适配器...+1 到@Nunu跨度>
-
考虑为列表中的每一行创建一个
DataItem类来将相关的数据片段保存在一起。然后将DataItem对象的数组/集合与ListView的适配器一起使用。