Android自定义listview与webview重置url
大家好,我正在寻找这个问题的解决方案...我有一个自定义列表视图,它是通过扩展 baseadapter 类并膨胀一个由 3 个控件组成的简单布局创建的 1 个
- Web 视图
- TextView
- imageview
在 web 视图中我将显示一个小的播放按钮图标,它将从远程播放一些 mp3。我需要做的就是重新加载列表视图中可用的所有 webview 控件... 希望你能理解我的问题是什么....
只要考虑一下这个场景..一旦页面加载,我单击第一个 webview,它将开始播放 mp3 歌曲,在它之前,如果我单击第二个 webview,两首歌曲都会播放同时...这不是我需要的。所以我认为唯一可能的解决方案是每次用户单击 webview 时重新加载页面中的所有 webview...
希望得到更好的回复... 提前致谢
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
- Web View
- TextView
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 reload() 方法来停止播放。要捕获 WebView 内按下按钮的事件,您应该使用 setWebViewClient() 或 setWebChromeClient() 并覆盖负责的方法。我认为是最后一张。更多这里:
http://developer.android.com/reference/android/webkit/WebView.html
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
不要重新加载每个 WebView,只需重新加载您想停止播放的那个即可。您需要跟踪首先访问的 WebView(您将从 onClick 方法获取视图对象),然后当单击第二个 WebView 时,在第一个 WebView 中加载第一个 url,并开始跟踪下一个。我认为重新加载 WebView 应该使用 AsyncTask 完成,以便它不会停止 UI 线程,也不会干扰任何其他进程。
这是第二种方法,我不太确定。
使用 Javascript 在 WebView 和客户端代码之间创建一个接口。然后在单击另一个 WebView 后重新加载 WebView。以下是 Android 页面的摘录:
这是我认为的一种解决方案,但它不是最好的。
参考:这里
我仍然不明白为什么你要使用 WebView你的目的。为什么不使用 Android UI 元素(例如
Button
、ImageView
等)并调用服务呢?相信我,这将为您节省很多解决方法。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:
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.