Hi I'm trying to override IME action to show search on virtual keyboard. My EditText
is in the control that is placed onto the activity.
Here is what I have:
<EditText android:i开发者_如何学Cd="@+id/txtSearch"
android:textSize="18dp"
android:textColor="@color/main_text_black"
android:layout_width="247dp"
android:layout_height="fill_parent"
android:imeOptions="actionSearch"
android:gravity="center_vertical"
android:singleLine="true"
android:background="@null"
android:layout_alignParentLeft="true"
android:layout_marginLeft="38px" />
In Code I have this listener set on the EditText
:
@Override
public boolean onEditorAction(TextView view, int arg1, KeyEvent arg2) {
if((arg1 == EditorInfo.IME_ACTION_SEARCH) {
for(OnSearchListener listener : _listeners) {
listener.OnSearch(view, getSearchString());
}
}
InputMethodManager imm =
(InputMethodManager)_context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
return false;
}
arg1
always comes back as 0
when I press the enter key, which is "unidentified". I also tried different keyboards like sendMessage and none of them work neither. What's going on?
Thank you in advance!
You need to specify android:inputType="text" attribute in xml file.
updated to droid 2.2 and it started working. Horrible bug!
精彩评论