get WebView instances stored in a ViewAnimator

394 views Asked by At

I have some WebView instances that i stored in a ViewAnimator programmatically. Firstly i constructed each WebViesw. Then i add them into the ViewAnimator

WebView webview = new WebView(context);
viewAnimator.addView(webview, index, layoutparams);

While a webView being added into the ViewAnimator, an AsyncTask instance is executed to load webpage from a specific URL.

My question, how can i get a webView from that ViewAnimator for a particular index value. I want to do some specific actions to the webView, such as reload or stop. I have done this way..

WebView currentWebView = (WebView) viewAnimator.getChildAt(index);
currentWebView.reload();

But the currentWebView returned null. Is that the right way to get webView instance from ViewAnimator? Please help...

1

There are 1 answers

0
Anasthase On

I don't know why getChildAt() return null, but as a workaround, you can maintain your own list of WebView. This is a stupid question, but are you sure your index is valid?