I tried to hide keyboard on onCreateView in my fragment (where there is my viewPager) with these solutions:
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
InputMethodManager mgr = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(windowToken, 0);
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
final InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mView.getWindowToken(), 0);
}
@Override
public void onPageScrolled(int position, float offset, int offsetPixels) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
but all these solution doesn't works, and, when editText is focused, the keyboard appears.
UPDATE: i try with these codes in the onCreatedView of the fragment
mViewPager.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
if (mViewPager.getCurrentItem() == 0) {
final EditText initialValue = (EditText) mViewPager.findViewById(R.id.initialValueEditText);
final EditText increase = (EditText) mViewPager.findViewById(R.id.increaseEditText);
initialValue.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
evalue = "1";
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
InputMethodManager imt = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imt.hideSoftInputFromWindow(initialValue.getWindowToken(), 0);
return true;
}
});
increase.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
evalue = "2";
return false;
}
});
}
return true;
}
});
and
view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
});
but unfortunatly when I focus the editText, the keyboard appears