http://hi.baidu.com/maguowei/blog/item/2a757f091af4e8bc2fddd414.html/cmtid/1244bd8f47ca7ce1f11f362d实现动态菜单….需要从sd卡中读取xml文件并解析出来….然后绘制界面
File f = new File(android.os.Environment.getExternalStorageDirectory()+”/ebsapp/menu.xml”); //后面是跟你在sd卡上存放的xml路径
String path=f.getAbsolutePath();
File myfile=new File(path);
if(myfile.exists())
{
hasFile=1;
}
FileInputStream fileIS = new FileInputStream(path);
StringBuffer sb=new StringBuffer();
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
String readString = new String();
//just reading each line and pass it on the debugger
while((readString = buf.readLine())!= null){
sb.append(readString);
}
//创建一个SAX的解析器
SAXParserFactory parsefac=SAXParserFactory.newInstance();
XMLReader reader=parsefac.newSAXParser().getXMLReader();
//为XMLreader创建解析容器
reader.setContentHandler(new MyContentHandler());//在这就要复写Handler类方法了.在各个事件中写自己想要实现的效果我的类叫MyContentHandler
//开始解析文件
String s1=sb.toString();
reader.parse(new InputSource(new StringReader(s1)));
另外注意xml文件的编码格式….android默认的是utf-8的…