- 浏览: 122826 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
kingbinchow:
android:tonghuaguanxin 写道请问,这个属 ...
修改EditText的光标颜色 -
tonghuaguanxin:
请问,这个属性在代码中如何设置?
修改EditText的光标颜色
<?xml version="1.0" encoding="utf-8"?> <products> <product> <id>10</id> <name>电脑</name> <price>2067.25</price> </product> <product> <id>20</id> <name>微波炉</name> <price>520</price> </product> </products>
public class Product { private int id; private String name; private float price; }
解析的主要代码
import java.util.ArrayList; import java.util.List; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class XML2Product extends DefaultHandler { private List<Product> products; // 该变量用于保存转换后的结果 private Product product; private StringBuffer buffer = new StringBuffer(); public List<Product> getProducts() { return products; } @Override public void characters(char[] ch, int start, int length) throws SAXException { buffer.append(ch, start, length); super.characters(ch, start, length); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { // 遇到<product>结点后将在startElement方法中创建的Product对象添加到List对象(products)中 if (localName.equals("product")) { products.add(product); } // 遇到<id>结点后将结点值赋给 Product.id 属性 else if (localName.equals("id")) { product.setId(Integer.parseInt(buffer.toString().trim())); buffer.setLength(0); // 必须清空缓冲区 } // 遇到<name>结点后将结点值赋给 Product.name 属性 else if (localName.equals("name")) { product.setName(buffer.toString().trim()); buffer.setLength(0); } // 遇到<price>结点后将结点值赋给 Product.price 属性 else if (localName.equals("price")) { product.setPrice(Float.parseFloat(buffer.toString().trim())); buffer.setLength(0); } super.endElement(uri, localName, qName); } @Override public void startDocument() throws SAXException { products = new ArrayList<Product>(); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // 当遇到<product>结点时创建 Product 对象 if (localName.equals("product")) { product = new Product(); } super.startElement(uri, localName, qName, attributes); } }
发表评论
-
android studio debug 一直加载so文件
2017-06-24 16:15 527以前在debug时,一直很快就可以成功,但最近电脑卡,加上更新 ... -
心形vector drawable
2016-04-21 10:44 575<vector xmlns:android ... -
Gridview的第一个Item点击没反应,点击其他的item OK
2015-08-07 14:56 1611遇到一个前人挖下的大坑,各种没响应的呀,后来发现以下代码有问题 ... -
仿iOS 的AssistiveTouch 按键 Floating Action Button
2015-04-16 14:50 1265FloatButton fb = new FloatBu ... -
Android 常见错误处理
2015-04-03 16:03 9051.could not find "com.baid ... -
Android GirdView 最后一行显示不完整
2015-03-20 18:19 3454Android GridView 设置wrap_content ... -
import android eclipse project to android studio
2014-11-13 11:09 884Export from Eclipse 1.Update y ... -
关于android应用退出的问题(转)
2014-10-06 15:48 1198看到很多关于应用退出的问题,今天在这里为大家简单总结一下,如果 ... -
Canvas.drawTextOnPath 2D绘图
2014-07-23 17:18 667绘制文字效果,如下图 protected void onD ... -
自定义menu,用PopupWindow截获KeyEvent
2014-07-17 15:49 1208public boolean onKeyDown(int ke ... -
Android 自动结束本层activity,回退到上一层 的intent 设置
2014-06-27 13:08 1916Intent intent = new Intent(); ... -
Android Custom View , can not use custom tag in xml file
2014-06-27 13:04 577add this line: xmlns:custom=&qu ... -
onMeasure()--典型视图度量时间
2013-02-18 15:42 950@Override protected void onMe ... -
AsynTask
2013-02-07 16:25 675... -
修改EditText的光标颜色
2013-01-29 15:02 4142在使用EditText的XML 文件中加入一个属性: and ... -
PopupWindow 的BadTokenException
2012-11-05 15:10 1275进入Activity就弹出PopupWindow 来,结果编译 ... -
android sqlite3 数据类型
2012-08-20 09:54 7063sqlite3中的数据类型 大多数的数据库引擎(到现在据我 ... -
android 入门xml布局文件--转
2012-07-10 15:58 869LinearLayout和RelativeLayout共有属性 ... -
Syntax error, static imports are only available if source level is 1.5
2012-06-05 10:20 1554Question: 工程之前一直正常运行,今早上 突然报出 S ... -
android--JNI (转)
2012-05-29 12:14 935The JNI is designed to handle s ...
相关推荐
Android SAX 解析XML SAX 解析XML(通用)
android sax解析xml 完整的例子及说明,解压后就可以运行,相信你的选择
android sax ,dom生成xml文件
android SAX解析XML
SAX解析XML文件的实例。一个项目同时用dom解析和sax解析xml文件貌似会报错,项目框架建一直是用sax和dom4j解析xml文件的。当我用dom解析xml文件。导入包后就报错识别不了xml文件的编码格式。于是做了一个sax解析xml...
android中用sax解析xml模板的demo源码,解压出来将解析类导入其他工程就可用了不必再写了.
使用SAX方式解析XML SAX 是读取和操作 XML 数据的更快速、更轻量的方 法。SAX 允许您在读取文档时处理它,从而不必等待整个文档被存储之后才采取操作。它不涉及 DOM 所必需的开销和概念跳跃。 SAX API是一个基于事件...
android用sax解析xml文件实例源码
android 使用 sax 去解析xml。
android xml解析,sax pull dom三个解析
Android之SAX解析
android使用SAX解析XML
Android 使用SAX实现XML的读和写,使用XML与后台交互,博文地址:http://blog.csdn.net/diyangxia/article/details/43524267
android 以SAX方式解析xml
Sax解析XML文件解
android sax解析创建xml源码,其中包含两种解析xml的方式。
读取和解析xml文件
android 使用sax解析XML,内含视频和源码已经说明文档。非常详细
Java SAX解析Xml Demo(详细注释)
使用sax解析从网络上获取的xml文件