Android WebView inside ListView onclick event issues
来源:互联网 发布:北京赛车数据接入 编辑:程序博客网 时间:2024/05/16 10:18
http://stackoverflow.com/questions/4973228/android-webview-inside-listview-onclick-event-issues
I have a ListView where each row has two webviews side by side, taking up the entire row. I've set up onListItemClick() in my ListActivity, but they are not fired when I tap on one of the rows (unless the place I happen to tap is outside the webview's border - but this isn't likely behavior, users would most likely want to tap on the image inside the webview).
I've tried setting setFocusable(false) and setFocusableInTouchMode(false), but those don't help.
Ideally this would operate exactly like Facebook's newsfeed, where you can tap on the profile picture of someone's wall post and it acts as if you've tapped the entire row (in FBs case the text for the wall post)
Figured it out, posting my solution in case someone else wants to do something similar:
I had to use an OnTouchListener, since OnClick and OnFocus weren't working. I extended a class that is reuseable:
private class WebViewClickListener implements View.OnTouchListener { private int position; private ViewGroup vg; private WebView wv; public WebViewClickListener(WebView wv, ViewGroup vg, int position) { this.vg = vg; this.position = position; this.wv = wv; } public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_CANCEL: return true; case MotionEvent.ACTION_UP: sendClick(); return true; } return false; } public void sendClick() { ListView lv = (ListView) vg; lv.performItemClick(wv, position, 0); } }
The sendClick method could be overridden to do what's needed in your specific case. Use case:
WebView image = (WebView) findViewById(R.id.myImage); image.setOnTouchListener(new WebViewClickListener(image, parent, position));
- Android WebView inside ListView onclick event issues
- Android SDK Tutorial: Button onClick Event
- On the Android ListView listSelector to solve cross-border issues
- CLR Inside Out Investigating Memory Issues
- Android 技巧 - listview 里面的图片不能响应onClick事件?
- Android ListView 子控件onClick正确获取position
- resmgr:cpu quantum Top Event Issues Solved
- JavaScript的onclick event handler
- function onclick(event) { ob('3'); }
- Inside Android
- 自定义ListView适配器onclick
- 自定义ListView适配器onclick
- 自定义ListView适配器onclick
- 【Github Issues】ffmpeg-android-java Issues
- Android, How to get redirection event in WebView?
- listview+webview
- Special issues in Android
- Android Issues List
- Java调用Windows控制台命令方法介绍
- Bash星号的那点事
- Ubuntu进程命令
- LFS学习(9)安装其他软件包
- hdu 4293
- Android WebView inside ListView onclick event issues
- android不用另建工程进行单元测试及改变测试方法执行顺序
- FckEditor配置手册中文教程详细说明 .
- Python脚本翻译英文到汉语
- Bash引号的那点事
- C# 无边框窗体的移动,任务栏右键菜单,调整大小
- 七夕,你拿什么拯救你的爱人?
- C++中的覆盖和隐藏
- ubuntu11.10 32bit 下android2.3 源码下载