简体   繁体   English

EditText-键盘未出现在焦点上

[英]EditText - keyboard doesn't appear on focus

I have this annoying problem. 我有这个烦人的问题。 My app has 2 activities (tabs) Activity1:listview, Activity2:editText+listview. 我的应用程序有2个活动(标签):Activity1:listview,Activity2:editText + listview。 App starts with Tab1(Activity1). 应用以Tab1(Activity1)开头。 When i open 2nd Activity (with edittext), no matter if EditText is selected or not (programmable), when i click on EditText, nothing happens (softKeyboard should appear). 当我打开第二个活动(带有edittext)时,无论是否选择EditText(可编程),当我单击EditText时,都不会发生任何反应(应该出现softKeyboard)。 Only solution is to change activity (click on Tab1 widget) and return to activity 2 - after this tab swap, keyboard works fine. 唯一的解决方案是更改活动(单击Tab1小部件)并返回活动2-在此选项卡交换之后,键盘可以正常工作。

Part of XML layout with edittext: 具有edittext的XML布局的一部分:

    <EditText
    android:hint="Wyszukaj..."
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:inputType="textAutoComplete|text"
    android:singleLine="true" 
    android:focusable="true"
    android:focusableInTouchMode="true"
>

and here is 2 overrided method from Activity2 这是来自Activity2的2个替代方法

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab2);

    this.db = DataBase.getInstance();
    this.ds = DataSource.getInstance();
    this.prepareListView();
}

@Override
protected void onResume() {
    super.onResume();
    this.doubleBackToExitPressedOnce = false;
}
private void prepareListView() {
    sbal = this.db.getAllStops();
    adapter = new StopListAdapter(this, sbal);

    lv = (ListView) findViewById(R.id.tab2list);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(onClick);
    EditText et = (EditText) findViewById(R.id.editText1);
    et.addTextChangedListener(changeWatcher);
    registerForContextMenu(lv);
}

Do you have any ideas, how XMLcode and activity code should look like in this case? 您有什么想法,在这种情况下XMLcode和活动代码应该是什么样子?

See this answer. 看到这个答案。 It solved the same problem for me: 它为我解决了同样的问题:

Keyboard not shown when i click on edittextview in android? 当我在android中单击edittextview时未显示键盘吗?

and try this code 并尝试此代码

mEditText.clearFocus();

The workaround for this, to explicitly call the soft keyboard on onCreate() and onResume() method. 解决方法是,显式调用onCreate()和onResume()方法上的软键盘。

 editText.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            if (editText.isEnabled() && editText.isFocusable()) {
                editText.post(new Runnable() {
                    @Override
                    public void run() {
                        Context context = getApplicationContext();
                        final InputMethodManager imm = 
          (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(editor,InputMethodManager.SHOW_IMPLICIT);
                    }
                });
            }
        }
    });

Hope this helps :) 希望这可以帮助 :)

try dropping out the two lines about "focusable" from xml. 尝试从xml中删除关于“ focusable”的两行内容。 i have something very similar and it works without them 我有一些非常相似的东西,没有它们也可以工作

try {
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(
                            YourEditText.getWindowToken(), 0);
                } catch (Exception e) {
                    e.printStackTrace();
                }

Try this with edittext... 尝试使用edittext ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM