Hi all, In my application I want to display a list of stuff and provide the user with the ability to filter the list by using the soft keyboard. To that end I added a popup with a button that should trigger (hide/ show) the soft keyboard for filtering. I don't want to have a visible edit text control, cause it would take up unnecessary space on the screen. Rather than that, I would like to display a toast showing the filter query as the user types, much as the 'android:textFilterEnabled' attribute for ListView does. To my understanding there is no obvious way of doing this with available Android components. So I tried the following approach (this is only the part for toggling soft keyboard):
1) creating a layout containing invisible edit text and the list view: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:id="@+id/list_container" style="@style/main" > <View class="com.blahblah.view.InsertTextView" <-- this is basically EditView android:id="@+id/filterbox" android:layout_width="0dp" android:layout_height="0dp" android:visibility="invisible" android:inputType="textFilter" android:imeOptions="flagNoExtractUi|flagNoEnterAction| flagNoAccessoryAction" android:focusable="true" android:focusableInTouchMode="true" /> <ListView android:id="@+id/mylist" android:drawSelectorOnTop="false" android:layout_height="0px" android:layout_width="fill_parent" android:layout_weight="5" /> </LinearLayout> - adding button as a popup and invoking InputMethodManager on click to toggle the soft input (called in onCreate): private void initButton() { Button buttonView = (Button) getLayoutInflater().inflate(R.layout.keyboard_button, null); buttonView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final View target = findViewById(R.id.filterbox); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // this does not work... // imm.toggleSoftInputFromWindow(target.getWindowToken(), InputMethodManager.SHOW_FORCED, 0); // ... so need to track this in an instance variable - which sucks if (imeShowing) { imm.hideSoftInputFromWindow(target.getWindowToken(), 0); imeShowing = false; } else { // check that the filterbox got focus Preconditions.checkState(target.requestFocusFromTouch()); Preconditions.checkState(target.hasWindowFocus()); Preconditions.checkState(target.hasFocus()); imm.showSoftInput(target, 0); imeShowing = true; } } }); buttonPopup = new PopupWindow(buttonView); // ... code to display the button as a popup } As mentioned in the code sample, the 'obvious' approach (calling toggleSoftInput) does not work, so I had to revert to this ugly if- else. This is however, a secondary problem. The primary problem is that when I run this in the emulator, the soft keyboard is displayed correctly, but as soon as I start typing in it, an intent to the google search activity is raised! And the typed characters appear in the Google search box displayed as a result. What is even more weird, this only happens the first time I type after deploying and running the app. I.e. if I go back to my app from the Google search box, everything works as expected (no redirects to the search box again). Before showing the display I make sure that the invisible edittext gets focus, so it _should_ be the target of the soft keyboard, right?? Does anyone have any idea what is happening here? Cheers, Dariusz -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en