سؤال

I've updated my app and now the listener doesn't work.
I use this activity with to similar actions:
1. EditText (IP-Adress) & AutoCompleteTextView (subnetmask)
2. EditText (IP-Adress) & AutoCompleteTextView (host count; without spinner)

This class extends NavigationDrawerActivity which I use with Intents to switch between this two and other ones.

The button works fine.

on Create of my main Activity

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 and other 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" />
هل كانت مفيدة؟

المحلول

DONE with this:

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;
    }
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top