-1

我有一个 android 片段,其中包含一个实现如下的 android AsyncTask 类

    protected class getGraph extends
        AsyncTask<GraphFragment, Void, GraphFragment> {
    @Override
    protected GraphFragment doInBackground(GraphFragment... params) {
        performance = getPerformance(sharename);
        return null;
    }

    protected void onPostExecute(GraphFragment Param) {

    }

}

现在我想将作为 ArrayList 的值性能返回给调用方法。我该如何实现?

4

4 回答 4

0

尝试这个:

(用您的数据的任何本机变量类型替换“字符串”)

protected class getGraph extends
    AsyncTask<GraphFragment, Void, List<String>> {

List<String> performance = new ArrayList<String>();

@Override
protected GraphFragment doInBackground(GraphFragment... params) {
    performance = getPerformance(sharename);
    return null;
}

protected void onPostExecute(List<String> Param) {

}

}

于 2013-10-18T09:34:01.607 回答
-1

采取这种方法

protected class getGraph extends
    AsyncTask<GraphFragment, Void, ArrayList<YOUROBJECT> {

    @Override
    protected ArrayList<YOUROBJECT> doInBackground(GraphFragment... params) {
       performance = getPerformance(sharename);
       return performance;
    }

    public void onPostExecute( ArrayList<YOUROBJECT> Param) {

    }
}

在您的其他 Class/MainActivity 中以这种方式调用它:

private void getSomething(){
    new getGraph({
        @Override
        void onPostExecute(ArrayList<YOUROBJECT> Param){
            //DO SOMETHING IN MAINACTIVITY
        }
    }).execute(); 
}
于 2013-10-18T09:32:26.443 回答
-1

这样做。。

protected class getGraph extends
    AsyncTask<GraphFragment, Void, ArrayList<String> {


    @Override
    protected GraphFragment doInBackground(GraphFragment... params) {
       performance = getPerformance(sharename);
       ArrayList<String> DATA=new ArrayList<String>();
       /*
       do the process and assign result in DATA
       */
       return DATA;
    }

    protected void onPostExecute( ArrayList<String> Param) {
     // Get your arraylist here.
    }
}
于 2013-10-18T09:45:36.523 回答
-1

使用以下代码。

public class calc_stanica extends AsyncTask<ArrayList<String>, Void, ArrayList<String>> {
ProgressDialog dialog;

    @Override
    protected void onPreExecute() {
        dialog = new ProgressDialog(baraj_mapa.this);
        dialog.setTitle("Calculating...");
        dialog.setMessage("Please wait...");
        dialog.setIndeterminate(true);
        dialog.show();
    }

    protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
        ArrayList<String> result = new ArrayList<String>();
        ArrayList<String> passed = passing[0]; //get passed arraylist

        // Assign data to your Arralist from your method
         result = getData();
        //Some calculations...do your stuff here.

        return result; //return result arraylist
    }

    protected void onPostExecute(ArrayList<String> result) {
        dialog.dismiss();
       // Get your arraylist here.
    }
于 2013-10-18T09:46:32.573 回答