I have a ListView and it is possible to use the hardware keyboard to filter out items. However what should I do for phones that don't have a hardware keyboard and only a virtual one? Is there a way to add a button that when pressed, the virtual keyboard shows up?
4 Answers
I was able to toggle the on-screen keyboard using the code below. I hope this is useful to someone.
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(0, 0);

- 892
- 10
- 13
One suggestion could be to just use a text entry box (EditText). That way a user can in theory type more than one character to narrow the search (and see what they've typed). To display the on-screen keyboard, all they need do is touch in the textbox. If that box was named "Search" or something similar, I believe it would be more intuitive to a user than a button.

- 4,578
- 6
- 24
- 30
There's a convention (for which maybe someone else can provide a reference — I couldn't find anything quickly) that holding the Menu hardware button brings up the soft keyboard.
Though this is seemingly device dependent. I know it works on the G1, but on my HTC Hero it doesn't work on the home screen (though HTC seem to have messed up a few shortcuts, like holding the Home button).
Anyway, I know other apps like ConnectBot mention and employ this convention for bringing up the virtual keyboard.

- 110,418
- 27
- 198
- 193
-
2Long press on menu was only intended to be a last resort compatibility thing for applications that at the time didn't know about soft keyboards. Applications written today should not rely on it. Because it is a compatibility mode, it puts the keyboard up in a different state than you problem expect -- for example the user needs to explicitly dismiss it rather than following the normal auto-dismiss rules while navigating through the UI. – hackbod Jan 01 '10 at 21:31
-
Thanks for the clarification (from an Android no less! ;)). So what would be the recommended UI solution for the original question? An explicit search/filter text box as bdls mentioned? – Christopher Orr Jan 01 '10 at 21:39
-
Adding a EditText box seems to work. I found a question at http://stackoverflow.com/questions/1737009/answer-to-making-a-nice-looking-listview-filter-on-android (the first answer) that gives a nice tutorial I'm following. – Tyler Jan 01 '10 at 21:53
Holding the menu-button seems to no longer work in Android 4.0 (IceCreamSandwich). This breaks filterable lists in lots of applications where the user now has no way of filtering the list anymore and needs to eyeball-grep through long, long lists.

- 2,550
- 2
- 22
- 28