我正在使用标签滑动我的活动问题我有一个硬件键盘用于我的手机当我尝试输入数据到编辑文本时它没有输入所以我使用onTouchListener()重新启用焦点编辑文本它工作正常,但用户必须至少触摸每一个编辑文本一次这是我的问题是否有任何方法来解决这个问题所以帽子焦点听众工作正常像活动的
我试过
public void onViewCreated(View view,Bundle savedInstanceState){super.onViewCreated(view,savedInstanceState); edit_mobilenor.postDelayed(new Runnable(){@Override public void run(){// TODO Auto-generated method stub edit_mobilenor.requestFocusFromTouch();}},400); 也没有用
答案 0 :(得分:2)
广泛搜索后,我发现错误是:TabHost在onAttachedToWindow()中注册一个OnTouchModeChangeListener,在离开触摸模式时会窃取焦点。
因此,要重新关注该编辑文本,有两种方法
1)you can use onTouchListener which will re produce focus for edit text like this
editText.onTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.requestFocusFromTouch();
return false;
}
}
2)you can remove the OnTouchModeChangeListener in onAttachedToWindow() using the following code
mTabHost.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
public void onViewDetachedFromWindow(View v) {}
@Override
public void onViewAttachedToWindow(View v) {
mTabHost.getViewTreeObserver().removeOnTouchModeChangeListener(mTabHost);
}
});
对于这个问题,答案是2个
答案 1 :(得分:0)
在Edittext中使用IME选项检查此链接
http://technet.weblineindia.com/mobile/using-edit-text-ime-option-in-android-app/