带有webview的Android自定义listview重置url

hi guys i have searching for the solution to this problem... I have a custom listview which is created by extending the baseadapter class and inflating a simple layout which consists of 3 controls 1

  1. Web View
  2. TextView
  3. imageview

And in the webview i will be displaying a small playbutton icon which will play some mp3 from remote.. All that i need to do is reload all the webview controls available in the listview... Hope you could understand what i problem is....

Just Consider this senario.. once the page loads i click on the first webview which will start playing mp3 song and before it if i click on the second webview both the songs will be played at the same time... which is not wat i need. so only possible solution that i think is to reload all the webview in the page everytime the user click the webview...

Hoping for the better reply... Thanks in advance

#0

You should use reload() method to stop playing. To catch event of pressing button inside the WebView you should use either setWebViewClient() or setWebChromeClient() and override the method responsible. I think the last one. More here: http://developer.android.com/reference/android/webkit/WebView.html

#1

Don't reload every WebView, just reload the one you wanna stop playing. You need to keep track of what WebView was accessed first (You'll get the view object from the onClick method), and then when the second one is clicked, load the first url in the first WebView, and start tracking the next. And I think reloading the WebView should be done using the AsyncTask so that it won't stop the UI Thread or it won't interfere with any other process.

Here is a second way, of which I am not so sure. Create an interface between the WebView and your client-side code using Javascript. Then reload the webview once another WebView is clicked. Here is the excerpt from Android page:

Binding JavaScript code to Android code

When developing a web application that's designed specifically for the WebView in your Android application, you can create interfaces between your JavaScript code and client-side Android code...

This is one solution I think, but it isn't the best.

Reference: Here

I still don't understand why you'd use a WebView for your purpose. Why not use an Android UI element, like Button, ImageView,etc, and call the service? It'll save you a lot of workarounds, believe me.