I have a layout which contains some views like this:
<LinearLayout>
<TextView...>
<TextView...>
<ImageView ...>
<EditText...>
<Button...>
</linearLayout>
How can I set the focus (display the keyboard) on my EditText
programmatically?
I've tried this and it works only when I launch my Activity
normally, but when I launch it in a TabHost
, it doesn't work.
txtSearch.setFocusableInTouchMode(true);
txtSearch.setFocusable(true);
txtSearch.requestFocus();
Try this:
http://developer.android.com/reference/android/view/View.html#requestFocus()
This worked for me, Thanks to ungalcrys
Show keyboard:
Hide keyboard:
use:
I couldn't get any of these answers to work on their own. The solution for me was to combine them:
I'm not sure why that was required for me -- according to the docs it seems that either method should have worked on their own.
showSoftInput
was not working for me at all.I figured I needed to set the input mode :
android:windowSoftInputMode="stateVisible"
(here in the Activity component in the manifest)Hope this help!