I have a MenuItem in my ActionBar , which is a reload icon. My Activity has a WebView , and I want the icon to start the animation when the WebView starts loading the web page and stops when it is finished. This includes clicking on links on a downloadable site. What I have so far works the first time I open a webpage, but if I leave Activity and load another webpage, the reload icon seems to double or I get a NullReference exception, T27>

Here is my code:
public class Browser extends SherlockFragmentActivity { private MenuItem refreshItem; private WebView mWebView; @Override public void onCreate(final Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.browser); mWebView = (WebView)findViewById(R.id.webview); mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.loadUrl("http://www.google.com"); mWebView.setWebViewClient(new WebBrowserClient()); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) {
The commented code is different from the way I tried to get it to work.
UPDATE:
After debugging this more, I set a breakpoint in the StartAnimation function, and sometimes it reached 7 times in a row, and in other cases it didn't. That doesn't make sense, as it should work for me. Perplexity ...
SOLUTION (SORT OF):
Updating the StartAnimation () function for this seems to fix this problem, but seems to be more suited to solve the ribbon problem:
private void StartAnimation() { if (refreshItem != null && refreshItem.getActionView() == null) { final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ImageView ivRefresh = (ImageView)inflater.inflate(R.layout.refresh_view, null); final Animation rotation = AnimationUtils.loadAnimation(this, R.anim.refresh); ivRefresh.startAnimation(rotation); refreshItem.setActionView(ivRefresh); } }
android android-webview menuitem android-animation
Kris b
source share