我怎样才能设置焦点(并显示键盘)上编程我的EditText [英] How can i set the focus ( and display the keyboard ) on my EditText Programmatically

查看:196
本文介绍了我怎样才能设置焦点(并显示键盘)上编程我的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局,其中包含的一些看法是这样的:

I have a layout which contains some views like this :

<LinearLayout>
<TextView...>
<TextView...>
<ImageView ...>
<EditText...>
<Button...>
</linearLayout>

我如何设置焦点(显示键盘)在我的的EditText 编程? 我已经尝试这样做,它的工作原理,只有当我启动我的活动通常情况下,但是当我启动它在 TabHost ,这是行不通的:

how can i set the focus( display the keyboard ) on my EditText programatically ? 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();

问候,

推荐答案

试试这个:

EditText editText = (EditText) findViewById(R.id.myTextViewId);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

<一个href="http://developer.android.com/reference/android/view/View.html#requestFocus()">http://developer.android.com/reference/android/view/View.html#requestFocus()

这篇关于我怎样才能设置焦点(并显示键盘)上编程我的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆