我的listview是时时刷新的,这导致了listview中的edittext不能点击编辑,通过如下方法解决了此问题,监测屏幕的变化,如果弹出软键盘,则不更新,问题解决。
监测屏幕的代码如下
ViewTreeObserver observer = rootView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int screenHeight = rootView.getHeight();
Rect rect= new Rect();
rootView.getWindowVisibleDisplayFrame(rect);
int visibleHeight = rect.height();
int heightDiff = screenHeight-visibleHeight;
isKeyboardShowing = heightDiff>screenHeight/4;
LogUtil.d("onGlobalLayout","heightDiff="+heightDiff+";isKeyboardShowing="+isKeyboardShowing);
}
});
edittext绑定数据的时候,做如下判断
if(etReagentAlarmVal.isFocused()) {
if(!isKeyboardShowing){
etReagentAlarmVal.setText(data.getReagentAlarmVal() + "");
}
}else{
etReagentAlarmVal.setText(data.getReagentAlarmVal() + "");
}
问题解决
标签:heightDiff,int,edittext,isKeyboardShowing,刷新,listview,rect From: https://blog.51cto.com/u_16843399/12127486