如何更新里面的AsyncTask类方法列表textviews? [英] How to update textviews of list inside AsyncTask class method?

查看:131
本文介绍了如何更新里面的AsyncTask类方法列表textviews?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本卡住。结果我有 FirstAsyncTask 的更新阵列改编 []结果
使用其他 ImageAdapter 更新荫图像。请参阅code详情结果
我想更新列表中的每个TextView的。 Follwoing code最新通报imageviews但不更新的TextView。我想这与TextView的中的setText改编 []我的结果更新
我使用以下内 onPostExecute code的 FirstAsyncTask

  ListAdapter适配器=新SimpleAdapter(MainActivity.this,DataList控件,
                    R.layout.list_item,编曲,新的INT [] {R.id.name,
                            R.id.email,R.id.mobile});setListAdapter(Ladapter);        //如何更新ARRAY ARR []的TextView ?????        名单=(ListView控件)findViewById(android.R.id.list);        //创建列表视图自定义适配器
        适配器=新ImageAdapter(MainActivity.this,msStringS);图像//更新
        //设置适配器列表视图
        list.setAdapter(适配器);


解决方案

就做了的AsyncTask类的postExecute方法

在doInBackground()返回要填充列表中的对象。

这将被传递给onPostExecute(),你可以有初始化列表适配器。

 私有类LoadList扩展的AsyncTask<太虚,太虚,列表与LT;弦乐>> {
        @覆盖保护名单<串GT; doInBackground(虚空...... PARAMS){
            ArrayList的<串GT; listContents =新的ArrayList<串GT;();            listContents.add(项目一);
            listContents.add(项目二);
            listContents.add(项目三);            返回listContents;
        }        @覆盖保护无效onPostExecute(列表<串GT; listContents){
            ListAdapter适配器=新SimpleAdapter(MainActivity.this,listContents,
                    R.layout.list_item,编曲,新的INT [] {R.id.name,
                    R.id.email,R.id.mobile});            mListView.setAdapter(适配器);
        }
    }

Stuck with this.
I have FirstAsyncTask which updates array arr[]
Iam updating images using another ImageAdapter . Please see code for details
I want to update each textview of List. Follwoing code UPDATES imageviews but does not update textview. I want to setText of this textview with arr[] I updated in
I am using following code inside onPostExecute of FirstAsyncTask:

ListAdapter adapter = new SimpleAdapter(MainActivity.this, dataList,
                    R.layout.list_item, arr, new int[] { R.id.name,
                            R.id.email, R.id.mobile });

setListAdapter(Ladapter);

        //HOW TO UPDATE TEXTVIEW WITH ARRAY arr[]?????

        list=(ListView)findViewById(android.R.id.list);

        // Create custom adapter for listview
        adapter=new ImageAdapter(MainActivity.this, msStringS);//updater of images
        //Set adapter to listview
        list.setAdapter(adapter);

解决方案

Do it in the postExecute method of the AsyncTask class

After doInBackground(), return the object that you want to populate the list.

This will then be passed to onPostExecute() and you can initialise the list adapter there.

private class LoadList extends AsyncTask<Void, Void, List<String>> {
        @Override protected List<String> doInBackground(Void... params) {
            ArrayList<String> listContents = new ArrayList<String>();

            listContents.add("Item one");
            listContents.add("Item two");
            listContents.add("Item three");

            return listContents;
        }

        @Override protected void onPostExecute(List<String> listContents) {
            ListAdapter adapter = new SimpleAdapter(MainActivity.this, listContents,
                    R.layout.list_item, arr, new int[] { R.id.name,
                    R.id.email, R.id.mobile });

            mListView.setAdapter(adapter);
        }
    }

这篇关于如何更新里面的AsyncTask类方法列表textviews?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆