在AsyncTask的多PARAMS

在AsyncTask的多PARAMS

本文介绍了安卓:在AsyncTask的多PARAMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要两个参数(LV和位置)传递给AsyncTask的doInBackground方法,但我不知道该怎么做...

I need to pass two params (lv and position) to a Asynctask doInBackground method but I don't know how do it...

LoadSound.execute(lv,position)
class LoadSound extends AsyncTask<**[ListView,int]**, String, String>

谢谢!

编辑:

我有一个ListView。如果你在一个项目播放声音单击(来自互联网)。

I have a listView. If you click in an item play sound (from Internet).

我想显示具有AsyncTask的一个progressDialog。

I would like show a progressDialog with Asynctask.

在doInBackground方法我有itemOnClick:

In the doInBackground method I have the itemOnClick:

HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);

为此我需要传递的LV和位置。

for this reason I need to pass lv and position.

推荐答案

试试你的的AsyncTask ,只要你创建你的对象你可以传递参数范围内创建一个构造。
事情是这样的:

try creating a constructor within your AsyncTask and whenever you create your object you can pass the parameters.Something like this:

MyAsyncTask asynctask = new MyAsyncTask(10, true, myObject);
//this is how you create your object

 public class MyAsyncTask extends AsyncTask<Void, Void, Void>{

        int a;
        boolean b;
        Object c;

        public MyAsyncTask(int a, boolean b, Object c){
            this.a = a;
            this.b = b;
            this.c = c;
        }

        @Override
        protected Void doInBackground(Void... params) {
            if(b)
                c = a;
            return null;
        }

    }

,然后你可以叫 asynctask.execute();

编辑:的阅读您的更新问题,我同意湿眶客使用服务例如播放背景声音后;还可以显示启动您AsynkTask(如果这个人是indefinetly)前一个进度对话框,并关闭它在你的postexecute。

After reading your updated question I agree to Squonk to use a Service for example to play a background sound; also you can show a progress dialog before launching your AsynkTask (if this one is indefinetly) and dismiss it on your postexecute.

这篇关于安卓:在AsyncTask的多PARAMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:08