想出来,发布我的解决方案,以防其他人想要做类似的事情:
我不得不使用OnTouchListener,因为OnClick和OnFocus不工作.我扩展了一个可重用的类:
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方法,以便在特定情况下执行所需的操作.用例:
WebView image = (WebView) findViewById(R.id.myImage);
image.setOnTouchListener(new WebViewClickListener(image,parent,position));