【问题标题】:Edittext have to be focus alwaysEdittext 必须始终是焦点
【发布时间】:2017-10-16 06:46:24
【问题描述】:

我有一个 EditText。我希望这个编辑文本始终处于焦点和可写状态。我怎么能做到这一点而不每次都触摸它?因为条码扫描器机器连续发送数据到这个应用程序。

anasayfa_barkod.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) &&
                    (i == KeyEvent.KEYCODE_ENTER)) {
                adapter.clear();
                adapter.notifyDataSetChanged();
                geciciListeyeEkle();
                listeyiYukle();
                adapter.notifyDataSetChanged();
                tutarYazdir();

                if(anasayfa_verilenUcret.getText().length()>0){
                    try{
                        String ucret=anasayfa_verilenUcret.toString();
                        String paraustu=String.valueOf(Double.parseDouble(ucret)-gelenSatis);
                        anasayfa_paraustu.setText(paraustu);
                    }catch (NumberFormatException e){
                        e.printStackTrace();
                    }
                }
                anasayfa_barkod.requestFocus(); //not working
                return true;
            }
            return false;
        }
    });

我尝试了很多方法。但所有方法都不起作用。我可以设置键盘可见但光标不在edittext上。

【问题讨论】:

标签: java android android-edittext focus


【解决方案1】:

我用enter link description here解决了我的问题

new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if ( anasayfa_barkod!= null) {
                            anasayfa_barkod.requestFocus();
                        }
                    }
                }, 1000);

【讨论】:

    【解决方案2】:

    如果您处于活动状态,请在您的 onCreate 方法中添加:

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT‌​_INPUT_STATE_ALWAYS_‌​VISIBLE);
    

    如果你在片段中使用这个:

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT‌​_INPUT_STATE_ALWAYS_‌​VISIBLE);
    

    【讨论】:

    • 试试这个:getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT‌​_INPUT_STATE_ALWAYS_‌​VISIBLE);EditText.requestFocus()EditText.performClicked()
    【解决方案3】:

    我想我可以帮忙。在 onCreate 方法中使用它

    editText.requestFocus();
    

    它对我有用。

    【讨论】:

    • 或者你可以使用这个EditText.setSelected(true);
    • 试试 EditText.setFocusable(true);
    • 把它放到你的xml中的editText标签android:setFocusable="true"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-24
    • 2015-12-28
    • 2011-12-26
    • 2012-02-27
    • 2021-07-17
    • 2013-12-25
    • 2018-11-24
    相关资源
    最近更新 更多