简体   繁体   中英

soft keyboard does not show and does not close when

i have a edittext for filtering list. And my problem is that when i click on edittext the keyboard doesn't show up and when i press enter it just wont close.

I'm filtering using this code:

adapt = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,veik);
    lv.setTextFilterEnabled(true);
ed.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
                // veikali.this.veik.getFilter().filter(s);
                 adapt.getFilter().filter(s);
            }
        });

          ed.setClickable(true);

Can you please tell me how can i show keyboard when i click on edittext and hide it when i press enter?

If you are using a TouchScreen phone, on touching the edittext the SoftKeyboard would come up. As for the second part of your query try the following:

ed.setOnKeyListener(new View.OnKeyListener()
    {

        @Override
        public boolean onKey(View editView, int keyCode, KeyEvent event)
        {
            Context mContext = MyClass.this;
            if( keyCode == KeyEvent.KEYCODE_ENTER ){
                InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(ed.getWindowToken(),0);
                return true;
            }
            return false;
        }
    })

This seems like a lot of extra work. I don't every remember having to give this functionality to my edittexts because it should be doing it by default.

Are you sure that the edittext to focusable and there isn't some type of view blocking it? If your using in a list view you may want to check out this thread Focusable EditText inside ListView

as simple solution, try to add the following attribute for activity's tag in AndroidManifest.xml :

android:windowSoftInputMode="stateVisible|adjustResize"

check this documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM