本文介绍了OnFocusChangeListener上的TextView阻拦其OnClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序的多个TextViews,我已经落实,OnFocusChangeListener和OnClickListener他们,但我注意到,OnFocusChangeListener阻止OnClickListener ..请告诉我,如果有任何解决办法,以避免这种情况,因为我有同时实现。
channelMenu.setOnFocusChangeListener(新View.OnFocusChangeListener(){
@覆盖
公共无效onFocusChange(查看视图,布尔B){ //Toast.makeText(getActivity(),\"changing焦点访谈,2000年).show();
如果(B)的{
channelMenu.setShadowLayer(GLOW,0F,0F,Color.WHITE);
mGroupCallback.OnGroupSelected(channelMenu.getText()的toString()); }否则如果(!B){
channelMenu.setShadowLayer(DIM,0F,0F,Color.WHITE);
}
}
}); channelMenu.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(查看视图){
如果(!channelMenuExpanded){ 如果(!ischannelSubMenuCreated){ createChannelSubMenu();
channelSubmenusContainer.setVisibility(View.VISIBLE);
channelMenuExpanded = TRUE;
}否则如果(ischannelSubMenuCreated){
channelSubmenusContainer.setVisibility(View.VISIBLE);
channelMenuExpanded = TRUE;
}
}其他{
channelSubmenusContainer.setVisibility(View.GONE);
channelMenuExpanded = FALSE;
}
mGroupCallback.OnGroupSelected(channelMenu.getText()的toString());
}
});
解决方案
除了点击监听器的,请尝试使用触摸侦听器。
tv.setOnTouchListener(新OnTouchListener(){ @覆盖
公共布尔onTouch(视图V,MotionEvent事件){
如果(event.getAction()== MotionEvent.ACTION_UP){
//调用的点击方法。
返回true。
}
返回false;
}
});
修改上面的code,以满足您的需求。
i have multiple TextViews in my app and i have implemented both OnFocusChangeListener and OnClickListener on them, but i am noticing that OnFocusChangeListener is blocking OnClickListener .. please tell me if there is any workaround to avoid this as i have to implement both.
channelMenu.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
//Toast.makeText(getActivity(),"changing Focus",2000).show();
if (b) {
channelMenu.setShadowLayer(GLOW, 0f, 0f, Color.WHITE);
mGroupCallback.OnGroupSelected(channelMenu.getText().toString());
} else if (!b) {
channelMenu.setShadowLayer(DIM, 0f, 0f, Color.WHITE);
}
}
});
channelMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!channelMenuExpanded) {
if(!ischannelSubMenuCreated){
createChannelSubMenu();
channelSubmenusContainer.setVisibility(View.VISIBLE);
channelMenuExpanded = true;
}else if(ischannelSubMenuCreated){
channelSubmenusContainer.setVisibility(View.VISIBLE);
channelMenuExpanded = true;
}
} else {
channelSubmenusContainer.setVisibility(View.GONE);
channelMenuExpanded = false;
}
mGroupCallback.OnGroupSelected(channelMenu.getText().toString());
}
});
解决方案
Instead of click listener, try using touch listener.
tv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_UP){
//Call your click method.
return true.
}
return false;
}
});
Modify the above code to suit your needs.
这篇关于OnFocusChangeListener上的TextView阻拦其OnClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!