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

AsyncTask异步实现(便利自己后续复习)

2013-09-11 
AsyncTask异步实现(方便自己后续复习)public class Main extends Activity {private LayoutInflater m_fla

AsyncTask异步实现(方便自己后续复习)
public class Main extends Activity {  
 
    private LayoutInflater m_flater = null;  
    private LinearLayout mFlash;  
 
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.flash);  
        mFlash = (LinearLayout) findViewById(R.id.mFlash);  
        mFlash.startAnimation(AnimationUtils  
                .loadAnimation(this, R.anim.fadeout));  
        m_flater = getLayoutInflater();  
        LoadMainTask task = new LoadMainTask(this);  
        task.execute("");  
 
    }  
 
    public View LoadMainView(LayoutInflater flater) {  
        View view = flater.inflate(R.layout.main, null);  
        Button btnOk = (Button) view.findViewById(R.id.BtnOk);  
        btnOk.setOnClickListener(new OnClickListener() {  
            public void onClick(View v) {  
                finish();  
            }  
        });  
        return view;  
    }  
 
    private class LoadMainTask extends AsyncTask<Object, Object, View> {  
        public LoadMainTask(Context context) {  
        }  
 
        protected View doInBackground(Object... params) {  
            View view = null;  
            view = LoadMainView(m_flater);  
            // 为了测试加了延时,大家可以在这一块加载资源,数据等  
            try {  
                Thread.sleep(3000);  
            } catch (InterruptedException e) {  
                e.printStackTrace();  
            }  
            return view;  
        }  
 
        // 执行完毕  
        protected void onPostExecute(View view) {  
            setContentView(view);  
        }  
    }  
 

热点排行