未调用setOnEditorActionListener

时间:2014-04-03 17:57:21

标签: android android-xml

我已经更新了我的应用,现在听众没有工作 我将此活动用于类似的行动:
1. EditText(IP-Adress)& AutoCompleteTextView(子网掩码)
2. EditText(IP-Adress)& AutoCompleteTextView(主机数; 不带微调器

此类扩展了我NavigationDrawerActivity使用的Intent以在 2 和其他之间切换。

按钮工作正常。

创建我的主要活动

public void onCreate(Bundle savedInstanceState) {
    //License and Google Analytics code removed

    setContentView(R.layout.activity_main);
    super.onCreate(savedInstanceState);
    context=this;

    calc_screenSize(); //for the padding in initialise_views

    initialise_views(); //with findViewById
    initialise_table(); //subnettable with 4 quads, among other code

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    btn_berechnen.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            standard_go(false, true);

            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(et_input_IP.getWindowToken(), 0);
            imm.hideSoftInputFromWindow(et_input_SNM.getWindowToken(), 0);
        }
    });

    et_input_SNM.setOnEditorActionListener(new OnEditorActionListener() {//not called - why?
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            Log.d("actionId",actionId+"");
            Log.d("actionId",EditorInfo.IME_ACTION_DONE+"");

            if (actionId == EditorInfo.IME_ACTION_DONE) {
                standard_go(false, true);

                return true;
            }

            return false;
        }
    }); 

    //license check code rmoved
}

activity_main.xml 和其他 activity_xxx.xml conains:

<EditText
        android:id="@+id/input_ipAdresse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/Button_berechnen"
        android:ellipsize="end"
        android:ems="10"
        android:gravity="right"
        android:hint="@string/input_ipAdresse"
        android:imeOptions="flagNoExtractUi"
        android:inputType="phone"
        android:paddingRight="@dimen/padding_small"
        android:textSize="@dimen/fontsize_medium" >

        <requestFocus android:layout_width="match_parent" />
    </EditText>

    <AutoCompleteTextView
        android:id="@+id/input_snm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/input_ipAdresse"
        android:ellipsize="end"
        android:ems="10"
        android:gravity="right"
        android:imeActionLabel="@string/Button_berechnen"
        android:imeOptions="actionDone|flagNoExtractUi"
        android:inputType="phone"
        android:paddingRight="@dimen/padding_small"
        android:textSize="@dimen/fontsize_medium" />

1 个答案:

答案 0 :(得分:1)

完成此事:

et_input_SNM.setOnKeyListener(new OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        Log.d("actionId","OnKeyListener: "+keyCode+" - "+KeyEvent.KEYCODE_ENTER);
        if(keyCode == KeyEvent.KEYCODE_ENTER) {
            standard_go(false, true);
            return true;
        }
        return false;
    }
});