I have clear button to clear EditText.
<Button
android:id="@+id/bClearText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="10dp"
android:onClick="clearEtSearch"
android:background="@drawable/delete" />
This method clears EditText:
public void clearEtSearch(View v) {
etSearch.setText("");
etSearch.requestFocus();
showKeyboard(etSearch);
}
I have taken code below from hiding and changed to show keyboard, but it is not working
private void showKeyboard(View view) {
InputMethodManager manager = (InputMethodManager) view.getContext()
.getSystemService(INPUT_METHOD_SERVICE);
if (manager != null)
manager.showSoftInputFromInputMethod(view.getWindowToken(), 0);
}
What I am doing wrong? Please give suggestions to correct my code.