【发布时间】:2013-01-10 11:55:27
【问题描述】:
我基本上有代码
new AsyncTask<Integer, Void, View>() {
@Override
protected View doInBackground(Integer... tabIds) {
return mInflater.inflate(R.layout.layout_name, null);
}
@Override
protected void onPostExecute(View result) {
super.onPostExecute(result);
root_layout.addView(result);
}
}.execute(tabId);
layout_name.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/white" >
<EditText
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
<Button
android:id="@+id/do_stuff"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
我得到InflateException: Binary XML file line #x: Error inflating class <unknown>。
如果我删除EditText,它可以在没有problems 的情况下使用。
我找不到原因(花了 2 小时)。
有人知道这是什么原因吗? 并希望有一个解决方案
【问题讨论】:
-
在工作线程上膨胀视图不是最好的主意,为什么需要这样做?
-
因为加载所有内容都需要一段时间。即使我从服务器得到了我需要的东西
-
无论如何,这行不通,因为Android UI框架不是线程安全的。
-
找到这个stackoverflow.com/questions/6691311/… 猜想我不得不限制显示的数量
标签: android android-asynctask android-edittext layout-inflater inflate-exception