首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android inflate 与 AsyncTask 有关问题

2012-12-16 
Android inflate 与 AsyncTask 问题现在发现一个很奇怪的问题我有一个layout文件,需要在异步线程中inflate

Android inflate 与 AsyncTask 问题
现在发现一个很奇怪的问题

我有一个layout文件,需要在异步线程中inflate出来,然后发送到主线程显示,但是奇怪的是,当Activity生成后,如果马上进行inflate,就会报错,inflateexception

郁闷的是,如果先在主线程中inflate一次,那么,再在异步线程中inflate就不会有问题,好奇怪啊,现在把xml和inflate代码贴出来,望高手帮忙解答

Inflate代码
View vwDragMainOrder = layoutInflate.inflate(
R.layout.pop_drag_mainorder, null);

layout文件

<?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="match_parent"
    android:orientation="vertical" >

    <RadioGroup
        android:id="@+id/et_pop_drag_mainorder_exceptiontypegroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/et_pop_drag_mainorder_batch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="分批货"
            android:textSize="24sp" />

        <RadioButton
            android:id="@+id/et_pop_drag_mainorder_unshippedoffload"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="未出库拉货"
            android:textSize="24sp" />

        <RadioButton
            android:id="@+id/et_pop_drag_mainorder_shippedoffload"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="已出库拉货"
            android:textSize="24sp" />
    </RadioGroup>

    <LinearLayout
        android:id="@+id/ll_pop_drag_mainorder_pcsremark"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="90dp"
            android:layout_margin="5dp"
            android:layout_height="wrap_content"


            android:text="件数备注"
            android:textSize="22dp" />

        <EditText
            android:id="@+id/et_pop_drag_mainorder_pcsremark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_pop_drag_mainorder_remark"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="90dp"
            android:layout_margin="5dp"
            android:layout_height="wrap_content"
            android:text="备注"
            android:textSize="22dp" />

        <EditText
            android:id="@+id/et_pop_drag_mainorder_remark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_pop_drag_mainorder_exception"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="90dp"
            android:layout_margin="5dp"
            android:layout_height="wrap_content"
            android:text="异常"
            android:textSize="22dp" />

        <EditText
            android:id="@+id/et_pop_drag_mainorder_exception"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>
[最优解释]
我觉得你第一次inflate了,第二次用的是缓存



inflate应该要在主线程中才行吧,猜的。。自己看源码
[其他解释]
inflate需要在主线程中调用
[其他解释]
你可以在Async线程中inflate。你只能在主线程中操作。
[其他解释]

引用:
我觉得你第一次inflate了,第二次用的是缓存

inflate应该要在主线程中才行吧,猜的。。自己看源码


这个第二次用的是缓存,能解释得清楚些么,很想了解背后的原理
[其他解释]
引用:
引用:我觉得你第一次inflate了,第二次用的是缓存

inflate应该要在主线程中才行吧,猜的。。自己看源码

这个第二次用的是缓存,能解释得清楚些么,很想了解背后的原理
单例模式会吧?单例模式你也可以说他第一次调用的时候new一个出来,第二次调用的时候,用的是缓存。具体。。。得看源码
[其他解释]
引用:
你可以在Async线程中inflate。你只能在主线程中操作。


能否说细点

热点排行