里面的ListView onclick事件问题的Andr​​oid的WebView [英] Android WebView inside ListView onclick event issues

查看:107
本文介绍了里面的ListView onclick事件问题的Andr​​oid的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView每行有两个webviews并排,占用了整个行。我已经设置了onListItemClick()在我的ListActivity,但是当我一敲就行之一,他们没有开除(除非我碰巧挖掘的地方是web视图的境外 - 但这是不太可能的行为,用户会最可能希望利用web视图内的图像)上。

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).

我试过设置setFocusable(假)和setFocusableInTouchMode(假),但这些并不能帮助。

I've tried setting setFocusable(false) and setFocusableInTouchMode(false), but those don't help.

在理想情况下,这将完全运行像Facebook的新闻源,在这里你可以点击某人的墙后的资料图片,它的作用就好像你挖整行(在FB的情况下,文本的墙后)

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:

我不得不使用一个OnTouchListener,因为的OnClick和聚焦状态不工作。我扩展一个类,它是可重复使用的:

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);
    }
}

该sendClick方法可以重写做什么是需要在特定的情况下。用例:

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));

这篇关于里面的ListView onclick事件问题的Andr​​oid的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆