当前位置:编程学习 > wap >>

android.view.InflateException异常

如题:

我在主线程(UI线程)中可以使用LayoutInflater的inflate(int resource, ViewGroup root)方法,来实例化resource对应的xml文件生成View对象。为了提供用户体验我想把inflate(...)的调用,放到另一个线程去生成View,发现报android.view.InflateException: Binary XML file line #88
在xml文件中第88行中的控件不能生成了

是不是inflate(int resource, ViewGroup root)这个方法对线程有什么特殊的要求?


--------------------编程问答-------------------- 是不是inflate(int resource, ViewGroup root)这个方法对线程有什么特殊的要求?

没什么要求!LayoutInflater 对象调用方法前,必须初始化上下文

不知道楼主初始化没!!!  --------------------编程问答--------------------
引用楼主 sea_sun_sea 的回复:
如题:

我在主线程(UI线程)中可以使用LayoutInflater的inflate(int resource, ViewGroup root)方法,来实例化resource对应的xml文件生成View对象。为了提供用户体验我想把inflate(...)的调用,放到另一个线程去生成View,发现报android.view.InflateException: Binary XML file l……



调用layoutInflater = this.getLayoutInflater();来获得LayoutInflater的实例的,this是主Activity的引用,这样可以吗? --------------------编程问答-------------------- ....应该要LayoutInflater.from(content   c)来获取填出实例吧。。 --------------------编程问答--------------------
引用 2 楼 sea_sun_sea 的回复:
引用楼主 sea_sun_sea 的回复:
如题:

我在主线程(UI线程)中可以使用LayoutInflater的inflate(int resource, ViewGroup root)方法,来实例化resource对应的xml文件生成View对象。为了提供用户体验我想把inflate(...)的调用,放到另一个线程去生成View,发现报android.view.InflateExce……


layoutInflater lay=layoutInflater.from(this)//this是主Activity的引用

View myView=lay.inflate(int resource, ViewGroup root)

这样的... --------------------编程问答--------------------
引用 2 楼 sea_sun_sea 的回复:
调用layoutInflater = this.getLayoutInflater();来获得LayoutInflater的实例的,this是主Activity的引用,这样可以吗?

文档上说可以,我试了下也没问题,在线程中调用也可以,你还是贴下你的xml吧
use getLayoutInflater() or getSystemService(String) to retrieve a standard LayoutInflater instance that is already hooked up to the current context --------------------编程问答-------------------- 学习了!
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,