Android - 如何在onAnimationEnd上执行类

时间:2014-03-06 22:26:16

标签: android android-asynctask android-animation

我有一个在onCreate()中创建的AsyncTask,它被称为GatherText()我有一个动画,可以将TextView滑出视图。当动画结束时,我希望它调用AsyncTask。

这是我的代码的基本概念

public class MainActivity extends Activity implements AnimationListener {
 public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);

 class GatherText extends AsyncTask<JSONObject, String, JSONObject> {

            @Override
            protected void onPreExecute() {
                super.onPreExecute();

            } 

            @Override
            protected void onProgressUpdate(String... values) {
                super.onProgressUpdate(values);

            } 

            }

            @Override
            protected void onPostExecute(JSONObject json) {

            }//end onPostExecute

        }//end GatherText Asynctask


   }//end onCreate


    @Override
    public void onAnimationEnd(Animation animation) {
        if(animation == slideout){
           //THIS IS WHERE THE ERROR OCCURS
                    new GatherText().execute();
               }
    }//End onAnimationEnd


}//end Main Activity

onAnimationEnd()方法中,我收到一条错误消息GatherText() can not be resolved to a type。如何在GatherText()之外拨打onCreate

1 个答案:

答案 0 :(得分:0)

将你的asynctask类放在onCreate

之外
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);



 }//end onCreate

class GatherText extends AsyncTask<JSONObject, String, JSONObject> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

        } 

        @Override
        protected void onProgressUpdate(String... values) {
            super.onProgressUpdate(values);

        } 

        }

        @Override
        protected void onPostExecute(JSONObject json) {

        }//end onPostExecute

    }//end GatherText Asynctask


@Override
public void onAnimationEnd(Animation animation) {
    if(animation == slideout){
       gathertext = new GatherText();
       new GatherText().execute();
    }
}//End onAnimationEnd