android xml解析添加到listview中的问题
一个问题不知什么原因,代码:
public class OtherActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_other);
//TextView tv1 = (TextView) findViewById(R.id.editText1);
//获取存入的xml字符串
String PaiMaiXML=load();
List<String> data = new ArrayList<String>();
data.add("车牌列表");
List<Map<String, Object>> PaiMaiList = new ArrayList<Map<String, Object>>();
Map<String, Object> PaiMaiMap = new HashMap<String, Object>();
ByteArrayInputStream tInputStringStream = null;
try
{
if (PaiMaiXML != null && !PaiMaiXML.trim().equals("")) {
tInputStringStream = new ByteArrayInputStream(PaiMaiXML.getBytes());
}
}
catch (Exception e) {
// TODO: handle exception
//tv1.setText(e.getMessage());
return;
}
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(tInputStringStream, "UTF-8");
int eventType = parser.getEventType();
//List<PaiMaiInfo> PaiMaiList=new ArrayList<PaiMaiInfo>;
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
// persons = new ArrayList<Person>();
break;
case XmlPullParser.START_TAG:// 开始元素事件
String name = parser.getName();
if (name.equalsIgnoreCase("Base_tabletNumber")) {
// currentPerson = new Person();
// currentPerson.setId(new
// Integer(parser.getAttributeValue(null, "id")));
//tv1.setText(parser.nextText());
PaiMaiMap.put("title", parser.nextText());
data.add(parser.nextText());
}
if(name.equalsIgnoreCase("Base_Family"))
{
PaiMaiMap.put("info", parser.nextText());
PaiMaiMap.put("img", R.drawable.ic_launcher);
PaiMaiList.add(PaiMaiMap);
PaiMaiMap = new HashMap<String, Object>();
}
// else if (currentPerson != null) {
// if (name.equalsIgnoreCase("loginlink")) {
// currentPerson.setName(parser.nextText());// 如果后面是Text节点,即返回它的值
// } else if (name.equalsIgnoreCase("errmsg")) {
// currentPerson.setAge(new Short(parser.nextText()));
// }
// }
break;
case XmlPullParser.END_TAG:// 结束元素事件
// if (parser.getName().equalsIgnoreCase("person")
// && currentPerson != null) {
// persons.add(currentPerson);
// currentPerson = null;
// }
break;
}
eventType = parser.next();
}
tInputStringStream.close();
// return persons;
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//ListView listView = (ListView) findViewById(R.id.listView1);
//listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data));
//setContentView(listView);
SimpleAdapter adapter = new SimpleAdapter(this,PaiMaiList,R.layout.listcell,
new String[]{"title","info","img"},
new int[]{R.id.title,R.id.info,R.id.img});
setListAdapter(adapter);
}
当我把51行的注释掉就可以了,求真相
改成String wee=parser.nextText(); 也是有问题,难道nextText()的原因。。。
nextText()不能重复执行,具体原因 再研究
android xml解析添加到listview中的问题的更多相关文章
- android XMl 解析神奇xstream 五: 把复杂对象转换成 xml ,并写入SD卡中的xml文件
前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...
- Android] Android XML解析学习——方式比较
[Android] Android XML解析学习——方式比较 (ZT) 分类: 嵌入式 (From:http://blog.csdn.net/ichliebephone/article/deta ...
- android XMl 解析神奇xstream 六: 把集合list 转化为 XML文档
前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...
- android XMl 解析神奇xstream 四: 将复杂的xml文件解析为对象
前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...
- android XMl 解析神奇xstream 三: 把复杂对象转换成 xml
前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...
- android XMl 解析神奇xstream 二: 把对象转换成xml
前言:对xstream不理解的请看:android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 1.Javabeen 代码 packa ...
- C# 将Access中时间段条件查询的数据添加到ListView中
C# 将Access中时间段条件查询的数据添加到ListView中 一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Col ...
- Android XML解析
解析XML有三种方式:Dom.SAX.Pull 其中pull解析器运行方式与SAX类似. 我们首先认识pull解析器:http://developer.android.com/intl/zh-cn/r ...
- Android XML解析器的问题
最近在项目中遇到了一个解析XML的问题,我们是用android自带的DOM解析器来解析XML的,但发现了一个android的问题,那就是在2.3的SDK上面,无法解析像<, >, 等字符串 ...
随机推荐
- [WinAPI] API 14 [获取、设置文件属性和时间]
>_< 为了获取文件属性,用户可以使用GetFileAttributes与GetFileAttributesEx函数. GetFileAttributesEx函数除了返回文件属性外,还返回 ...
- [C++] socket -9[匿名管道]
::怎么弄都不能读取信息....先把代码放着.... #include<windows.h> #include<stdio.h> int main() { HANDLE rea ...
- [WinAPI] 串口读写
#include <stdio.h> #include <stdlib.h> #include <windows.h> HANDLE hComm; OVERLAPP ...
- 西安.NET俱乐部群 推广代码
CSS: .gallery-item { display:inline-block; margin: 15px; } 个人签名: <div class="gallery&quo ...
- error C3861: “LOG4CPLUS_DEBUG”: 找不到标识
头文件#include <log4cplus/loggingmacros.h>解决问题
- MyEclipse8.6中提交SVN报错
上周五(11月27日)的时候,从TortoiseSVN提交项目报错,然后直接从MyEclipse中检出来,修改后提交同样报错. MyEclipse8.6中提交SVN报错,错误提示如下: commit ...
- JS深入了解闭包
闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作 ...
- linux 下查找大于100M的文件(转)
命令行如下 find . -type f -size +1000000k Linux系统下查找大文件或目录的技巧 当硬盘空间不够时,我们就很关心哪些目录或文件比较大,看看能否干掉一些了,怎么才能知道呢 ...
- 使用Enitity Framework实现增删改查服务中的一些通用思路
添加 → 方法参数中有一个有关添加视图模型类型的形参,比如vm→ 根据vm的某个属性,比如Name判断在上下文中是否存在,如果不存在就抛EntityNotFoundException异常→ 判断vm所 ...
- Java 周历日历
WeekCalendarUtils工具类代码,传入起始日期即可返回对应日期的周历日历,年月部分添加周数统计 import java.util.Calendar; import java.util.Da ...