鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 手机系统开发 > android > >

android xml解析添加到listview中的问题

来源:互联网 作者:佚名 时间:2013-09-11 07:12
一个问题不知什么原因,代码: OtherActivity extends ListActivity { 2 3 @Override onCreate(Bundle savedInstanceState) { 5 super .onCreate(savedInstanceState); 6 // setContentView(R.layout.activity_other); TextView tv1 = (TextView) findViewBy

一个问题不知什么原因,代码:

OtherActivity extends ListActivity { 2 3 @Override onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 //setContentView(R.layout.activity_other); TextView tv1 = (TextView) findViewById(R.id.editText1); String PaiMaiXML=load(); 11 List<String> data = new ArrayList<String>(); 12 data.add("车牌列表"); 13 14 List<Map<String, Object>> PaiMaiList = new ArrayList<Map<String, Object>>(); 15 Map<String, Object> PaiMaiMap = new HashMap<String, Object>(); 16 17 ByteArrayInputStream tInputStringStream = null; { 20 if (PaiMaiXML != null && !PaiMaiXML.trim().equals("")) { 21 tInputStringStream = new ByteArrayInputStream(PaiMaiXML.getBytes()); 22 } 23 } 24 catch (Exception e) { 25 // TODO: handle exception ; 28 } 29 XmlPullParser parser = Xml.newPullParser(); 30 try { 31 parser.setInput(tInputStringStream, "UTF-8"); 32 int eventType = parser.getEventType(); (eventType != XmlPullParser.END_DOCUMENT) { 37 switch (eventType) { 38 case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理 ; String name = parser.getName(); (name.equalsIgnoreCase("Base_tabletNumber")) { 45 // currentPerson = new Person(); 46 // currentPerson.setId(new 47 // Integer(parser.getAttributeValue(null, "id"))); PaiMaiMap.put("title", parser.nextText()); 51 data.add(parser.nextText()); 52 53 } 54 if(name.equalsIgnoreCase("Base_Family")) 55 { 56 PaiMaiMap.put("info", parser.nextText()); 57 PaiMaiMap.put("img", R.drawable.ic_launcher); 58 PaiMaiList.add(PaiMaiMap); 59 PaiMaiMap = new HashMap<String, Object>(); 60 } 61 // else if (currentPerson != null) { 62 // if (name.equalsIgnoreCase("loginlink")) { 如果后面是Text节点,即返回它的值 64 // } else if (name.equalsIgnoreCase("errmsg")) { 65 // currentPerson.setAge(new Short(parser.nextText())); 66 // } ; 69 case XmlPullParser.END_TAG:// 结束元素事件 70 // if (parser.getName().equalsIgnoreCase("person") 71 // && currentPerson != null) { 72 // persons.add(currentPerson); 73 // currentPerson = null; ; 76 } 77 eventType = parser.next(); 78 79 } 80 tInputStringStream.close(); } catch (XmlPullParserException e) { e.printStackTrace(); 85 } catch (IOException e) { e.printStackTrace(); 88 } 89 //ListView listView = (ListView) findViewById(R.id.listView1); 90 //listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data)); SimpleAdapter adapter = new SimpleAdapter(this,PaiMaiList,R.layout.listcell, 93 new String[]{"title","info","img"}, []{R.id.title,R.id.info,R.id.img}); 95 setListAdapter(adapter); 96 97 } ,

网友评论
<