Android 从Asynctask更改listview Ui的项

Android 从Asynctask更改listview Ui的项,android,android-listview,android-asynctask,Android,Android Listview,Android Asynctask,大家好,安卓开发者 我尝试更改AsyncTask中Listview的每一行,并将其下载状态显示为: public OnlineStoreAdapter extends ArrayAdapter<MusicDownloadStructure>{ public View getView(int position, View view, ViewGroup parent) { // TODO Auto-generated method stub

大家好,安卓开发者
我尝试更改AsyncTask中Listview的每一行,并将其下载状态显示为:

public OnlineStoreAdapter extends
    ArrayAdapter<MusicDownloadStructure>{ 
    public View getView(int position, View view, ViewGroup parent) {
        // TODO Auto-generated method stub
        final MusicDownloadStructure data = ModelDownloadData[position];
        data.setStatusTextView((TextView) convertView
            .findViewById(R.id.tab2_downloadProgressText))T;
         .
         .
        Downloadbtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            downloadmanager = new ModelDownload(URL, data);
           downloadmanager.execute(); 
        }
   }
}

问题如何从另一个线程(Asynctansk)更改Listview UI并更新它

首先,让我们了解AsyncTask的OnProgressUpdate方法,例如:

@Override
protected void onProgressUpdate(Integer... values)
{
    int current = values[0];
    int total = values[1];
    float percentage = 100 * (float) current / (float) total;

    update listview download progress here...
    tv.setText((int) percentage);//Just an example, you might to do a cast to a string...
}
然后,在AsyncTask的doInBackground方法中,更新进度,如下所示:

publishProgress(current,total);

这将更新进度。如果AsyncTask是从不同的上下文运行的,则可以使用处理程序将消息发送回listview的上下文/活动。

会出现什么错误?请发布完整的getViewcode@BlazeTama没有任何错误,但我的视图在下载完成时没有更改,正如您所看到的,也有setText()方法,但这不是我的问题我的问题是我的Ui没有更改,所以我在POST上声明了setText()method@FxRi4,则必须使用处理程序。在ui线程上定义一个处理程序,并向处理程序发送更新消息,然后处理程序将从那里更新listview。
publishProgress(current,total);