0
我有一些的AsyncTask類,從業務執行:如何更改AsyncTask中的ListView?
public class DownloadTask extends AsyncTask<Void, Integer, Boolean {
@Override
protected Boolean doInBackground(Void... arg0) {
// do something
publishProgress(i);
}
@Override
protected void onProgressUpdate(Integer ... progress) {
if(textView()!=null) getTextView().setText(i + "%");
}
public void setTextView(TextView textView) {
this.textView = textView;
}
}
而且ListAdapter,在方法getView()
我使用方法的AsyncTask的setTextView()
TextView的設置中的AsyncTask:
public class DownloadTasksAdapter extends BaseAdapter {
private final Activity context;
private DownloadTask[] downloadTasks;
public DownloadTasksAdapter(Activity context, DownloadTask[] downloadTasks) {
this.context = context;
this.downloadTasks = downloadTasks;
}
public int getCount() {
return downloadTasks.length;
}
public DownloadTask getItem(int position) {
return downloadTasks[position];
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getLayoutInflater();
final View rowView = inflater.inflate(R.layout.downloads_listview_row, parent, false);
final TextView progressTxt = (TextView) rowView.findViewById(R.id.downloads_listview_row_progress);
switch (downloadTasks[position].getStatus()) {
case RUNNING:
downloadTasks[position].setTextView(progressTxt);
break;
}
return rowView;
}
}
的AsyncTask從業務執行,但是當我打開包含ListView的Activity時,AsyncTask應該更新一些字段,我怎麼能做到這一點? :(
OMG後!!!!!我想吻你:)謝謝VEEEEERYYYY MUCH!我找不到答案!萬分感謝! – ruslanys
hahaaaaa cooollll – Sandy09