Ajay
Ajay

Reputation: 1189

How to hide default keyboard from ListViewAdapter in android

I am using ListViewAdapter for binding ListView on my home page, and a custom keyboard. But when I clicked on EditText, the default keyboard displays.

I tried to hide it by using the following code:

InputMethodManager mgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
                    mgr.hideSoftInputFromWindow(diesel.getWindowToken(), 0);

activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

But it didn't work.

How can I hide the default keyboard from ListViewAdapter?

Upvotes: 6

Views: 3586

Answers (3)

karan vs
karan vs

Reputation: 3364

If you want to hide the keyboard on events like click of button, use this

public void onClick(View v)
{
     InputMethodManager imm = (InputMethodManager) v.getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

Upvotes: 5

Ajay
Ajay

Reputation: 1189

Finally i got it. i solved this problem. just added below line in ListViewAdapter.

(EditTextName).setInputType(0);

Now it will not open Default Keyboard on EditText Click or Touch.

Upvotes: 5

Marcin Orlowski
Marcin Orlowski

Reputation: 75646

Adapter is not the right place to do any UI related activities.

Upvotes: 4

Related Questions