1

I have an app which converts meters to centimeters , simple, right?

So i have two parts on it. One being the keypad and the other one are the two edittext boxes.

i was using my own keypad, so there was no sense for android keyboard to show up.

I looked upon various answers and they don't seem to work for me.

This question asks the same thing and i implemented the selected answer but the edittexts are behaving weirdly.

enter image description here

First one seem to work as i wanted it to work but somehow the other text won't come on focus.

I try to click on it and nothing happens.The focus just won't go from the first one.

What i tried

    findViewById(R.id.lengthConverterSecond).setOnTouchListener(this);
    findViewById(R.id.lengthConverterFirst).setOnTouchListener(this);
@Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return true;
    }

What's up with this weird behavior?

What would be the solution to my above problem?

update

Tried this tooo.

Just in case

findViewById(R.id.lengthConverterSecond).setOnFocusChangeListener(this);         findViewById(R.id.lengthConverterFirst).setOnFocusChangeListener(this);
    @Override
        public void onFocusChange(View view, boolean b) {
            if(b){
                InputMethodManager im=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                assert im != null;
                im.hideSoftInputFromWindow(view.getWindowToken(),0);
            }
        }

This doesn't work at all, like it won't hide the keyboard but that weird behavior i witnessed above,doesn't happen now.

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
Tilak Raj
  • 1,369
  • 5
  • 31
  • 64

1 Answers1

3

for minSdk=8 and maxSdk=23

 <EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:focusableInTouchMode="false"/>

for API 21 or >21

If you are having two edit text ( suppose editText1 and editText2) and you want to use your own custom keyboard then use this solution.

 EditText editText1 = findViewById(R.id.editText1);
 EditText editText2 = findViewById(R.id.editText2);

 editText1.setShowSoftInputOnFocus(false);  // add this if you dont want default keyboard when you tap on editText1.

 editText2.setShowSoftInputOnFocus(false);// add this if you dont want default keyboard when you tap on editText2.

here

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29