问题描述
我目前正在对抗Android上阿比拉特8 OnLongClickListener。
I'm currently fighting against the OnLongClickListener on Android Api Lvl 8.
取本code:
this.webView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
System.out.println("long click");
return true;
}
});
它完美。我可以在任何地方preSS的web视图和事件触发每次。
It works perfectly. I can press anywhere on the WebView and the event triggers every time.
现在来看看这个:
this.webView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final EditText editText = getUrlTextField();
switch (editText.getVisibility()) {
case View.VISIBLE:
editText.setVisibility(View.GONE);
return true;
case View.GONE:
editText.setVisibility(View.VISIBLE);
return true;
default:
return false;
}
}
});
假设URL的EditText组件是当前可见的,它得到了从显示器,应再次显示的时候又是漫长的单击事件被触发。但是,如果你运行它,该事件只是工作一次(!)当一个执行长按上的web视图的任何位置。为了使事情变得复杂,漫长的点击再次工作时,它是在网站上的链接...
Assuming the URL EditText components is currently visible, it gets gone from the display and should be shown again when another long click event is triggered.But if you run this, the event just works once (!) when one performs a long click on any position on the WebView. To make things complicated, the long click works again when it is performed on a link on the website...
任何人都可以解释,如果它是和/或是否有一个错误在我思考如何OnLongClickListener工作在SDK中的错误?!? :/
Can anyone explain if it is a bug in the sdk and/or if there is a mistake in my thinking how the OnLongClickListener is working?!? :/
编辑:
我已经在Nexus One的运行现在几个不同的方案,并得出以下conclussion:更改布局上运行时或多或少地杀死OnLongClickListener ...我还没有找到一种方式来获得它的工作可靠的。 ..
I've run now several different scenarios on a Nexus One and come to following conclussion: Changing the layout on runtime more or less kills the OnLongClickListener... I haven't found a way to get it work reliably at all...
我真的AP preciate,如果有人可以给我一个提示......我在我束手无策:(
I would really appreciate if anyone could give me a hint... I'm at my wits end :(
推荐答案
Personnally,我结束了由各重新布局后,重新设置监听器。
Personnally, I ended up by re-setting the listener after each relayout.
这篇关于安卓OnLongClickListener奇怪的/不可靠行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!