简体   繁体   English

TextEdit OnFocusChangeListener

[英]TextEdit OnFocusChangeListener

I am trying to get the keyboard to come up when an editText view gets or has focus. 我试图使键盘在editText视图获得焦点时出现。 I am getting the error getOnFocusChangeListener in view cannot be applied to anonymous android.view.View.OnFocusChangeListener getOnFocusChangeListener in view cannot be applied to anonymous android.view.View.OnFocusChangeListener收到错误getOnFocusChangeListener in view cannot be applied to anonymous android.view.View.OnFocusChangeListener

The error starts on new View.OnFocusChangeListener() and goes through the whole class. 错误new View.OnFocusChangeListener()开始,并遍历整个类。 I can't figure out why or how to get this working. 我不知道为什么或如何使它工作。

Here is my code: 这是我的代码:

final EditText measurement = (EditText)dialog.findViewById(R.id.measurement);

measurement.getOnFocusChangeListener(new View.OnFocusChangeListener(){
   @Override
   public void onFocusChange(View v, boolean hasFocus){
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      if(hasFocus){
         imm.showSoftInput(measurement, InputMethodManager.SHOW_IMPLICIT);
      }else{
         imm.showSoftInput(measurement, InputMethodManager.HIDE);
      }
   }
});

Please help me fill in the gaps in my knowledge about why this isn't working 请帮助我填补我的知识上的空白,以了解为什么它不起作用

instead of 代替

 measurement.getOnFocusChangeListener
 // you have to use
 measurement.setOnFocusChangeListener 

also you dont need to set a listener for edit text. 您也不需要设置用于编辑文本的侦听器。 whenever a edit text is clicked the softkeyboard will show up by itself, unless you are modifying certain behavior. 每当单击编辑文本时,软键面板都会自动显示,除非您要修改某些行为。

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

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