我必须填写ListView需要时间收集的文本信息。我的方法是使用 AsyncTask 来做后台工作,但是当结果到达时将文本设置为 TextView 会减慢列表的速度:每次getView()调用列表都会滞后。
这是我的AsyncTask课
private class BreadcrumbTask extends AsyncTask<FFile, Void, String>{
    private WeakReference<TextView> mTextView; 
    public BreadcrumbTask(TextView textView){
        mTextView = new WeakReference<TextView>(textView);
    }
    @Override
    protected String doInBackground(FFile... params) {
           // text processing
    }
    @Override
    protected void onPostExecute(String result) {
        if (mTextView != null){
            TextView tv = mTextView.get();
            if (tv != null)
                //this line blocks the UI. if I comment it the lag is gone
                tv.setText(result); 
        }
// mTextView.setText(结果); }
我在 getView() 中创建了一个新任务并执行它。问题显然来自tv.setText(result)于onPostExecute(). 当我发表评论时,列表很流畅。那么如何在TextView不减慢 UI 的情况下更新呢?