2014-09-25 71 views
0

当用户点击刷新图标时,计划用于刷新图标开始动画,但是,当我实现动画功能时似乎出现错误; “AnimationUtils类型中的方法loadAnimation(Context,int)不适用于参数(new View.OnClickListener(){},int)”。动画刷新图标

下面是代码片段。如何从动画源中加载动画,而不会出现上述错误,同时仍保留onClickListener框架。

final ImageView refreshBtn= (ImageView) findViewById(R.id.spin_refresh); 
    Log.i("RootActivity:setupHeader","******ImageView refreshBtn******"); 
    //Listening to Button Click by User 
    refreshBtn.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      //To set new INTENT on calling Methods in UPDATE & DOWNLOADSERVICE 
      ..... 

      //Perform Refresh Animation 
      LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      ImageView iv = (ImageView)inflater.inflate(R.layout.header, null); 

      //ISSUE IS AT .loadAnimation not able to be implemented. 
      Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate_refresh); 
      rotation.setRepeatCount(Animation.INFINITE); 
      iv.startAnimation(rotation); 
      item.setActionView(iv); 

      //ALERT DIALOG TO INFORM USER THAT REFRESH FUNCTION HAS BEEN CALLED 
      ....... 
     } 
    });  

回答

0

变化

Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate_refresh); 

Animation rotation = AnimationUtils.loadAnimation(YourActivity.this, R.anim.rotate_refresh); 

的原因是,在你的代码点,thisView.OnClickListener,而不是你的活动。

+0

感谢您的帮助 – 2014-09-25 03:59:59

0

这是指OnclickListner有

它的变化对上下文

Animation rotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_refresh);