I have two EditText in my actvity_main, clicking on it I want to disable the soft keyboard of the android. To achieve this functionality, I was following this link.
The two EditText has following id assigned to it
firstText and secondText
This is the code I applied to both the editText
firstText.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.onTouchEvent(event);
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return true;
}
});
For secondText only the name changes. For both the EditText soft keyboard does not show. Which is exactly what I want, But I want the cursor too. In which case, firstText does not show the keyboard but has the cursor. for secondText I am not able to retain the cursor.
I tried printing values inside if condition and setOnTouchListener. They both works perfectly all right.
Can someone help me on where I am going wrong?
Thanks! in advance