hai每一个。我是Android新手。在我的项目中,我阅读XML文件时遇到了一些问题。在我的xml中,我包含了一些音频和视频路径,并且我想通过代码读取xml文件,并且如果有一些音频或视频文件,我想在我的视图中显示一些图像。可以在任何机构的电话如何阅读XML文件。 请多关照检查xml中的资源并显示android中的资源的图标
0
A
回答
1
好首先你需要创建一个解析器下面是代码来做到这一点:
公共静态无效readTemplateFile(上下文的背景下){
/**
Include File Checking
*/
try {
XML_Handler_Template myExHan = new XML_Handler_Template();
InputStreamReader isr = new
FileReader(new File(Environment.getExternalStorageDirectory().getPath() + "/Library Template.xml"));
XML_Handler_Template.context = context;
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler((ContentHandler) myExHan);
xr.parse(new InputSource(isr));
} catch (Exception e) {
Toast.makeText(context, ">" + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
然后,您需要一个处理程序类。在上面的例子中,我的类被称为XML_Handler_Template。 (新文件(Environment.getExternalStorageDirectory()。getPath()+“/FILEPATH/FILE.XML”));}};}};}}
这里是此刻却是空白的XML_Handler_Class:
进口org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler;
公共类XML_Handler_Template扩展了DefaultHandler {
public static Context context = null;
@Override
public void startDocument() throws SAXException {
//this is called when the document is first read
}
@Override
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
//This is called when a new Tag is opened
//localName holds the Tag Name, the Value is got from the
//Characters function at the end of this class
//the attributes for each tag are stored in the atts array, you can either handle the attribute values here or pass the information to a separate function to handle them,
if (atts.getLength()>0){
for (int i=0;i<atts.getLength();i++){
addAttrib(atts.getLocalName(i) , atts.getValue(i)) ;
}
}
}
@Override
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
//This is called when a Tag is closed
}
@Override
public void endDocument() throws SAXException {
//this is called when the document is closed
}
@Override
public void characters(char ch[], int start, int length) {
//This is where the value of a Tag are read
String value = new String(ch , start , length);
// You may want to include a replaceAll("\r","") and replaceAll("\n","") to remove any hidden chars
}
}
有这样的发挥,看看你的身体情况如何,现在= 0),我通过上下文的类,所以虽然我是学我可以用敬酒向我展示正在阅读的价值。
相关问题
- 1. 如何检查Android资源资源?
- 2. Android - 从资源drawable中显示图像
- 3. 资源内置Android资源中的$ NotFoundException?
- 4. 资源检查
- 5. 检查是否显示数组中的资源ID并点击它(Android-Espresso)
- 6. xml资源中的警告
- 7. Android字符串资源中的XML?
- 8. Android中的位图:用于显示为50dp的资源大小
- 9. 的Android查找资源
- 10. 在Java Swing中显示资源图像
- 11. 在web资源中显示url图像
- 12. 的Android资源$ NotFoundException:资源ID#0x7f020052
- 13. Android:Howto获取Android资源的资源ID
- 14. Xamarin.Forms Android资源$ NotFoundException对于可绘制的xml资源
- 15. WPF:GroupBox标题中的资源
- 16. 显示资源问题的图像
- 17. 如何从XML资源中的矢量图像检索位图
- 18. 从nl.siegmann.epublib获取资源的位图资源加载资源
- 19. WinForms中的图像资源
- 20. 如何检查Azure资源的资源删除操作结果
- 21. 资源管理器不显示XML
- 22. 的Android资源ID
- 23. 查询Qt资源集合(.qrc)中的资源数量
- 24. 显示资源地图图像
- 25. Android:检查背景资源可绘制
- 26. 如何检查一个XML文件中的资源的Android工作室
- 27. 从Android的原始资源获取Xml
- 28. Asp.net中的资源
- 29. 检查OpenGL资源泄漏
- 30. 检查/比较imagebutton资源
k谢谢。我有存储在SD卡上,我想显示相关的音频\视频图标。 – user493244 2010-12-21 08:11:28
好吧有几件事情需要实施 – 2010-12-21 20:36:58
好吧,有很多事情需要你去处理。 1. XML解析 2.可绘图(不同设备需要的图标和规格) 3.视图和充气器。添加自定义ListItems到列表视图或动态添加视图到ScrollView 你是否熟悉上述任何一个? – 2010-12-21 20:47:21