Rushi Ayyappa
Rushi Ayyappa

Reputation: 2848

how to avoid "actionDone" for EditText

I am trying to display softkeyboard for my EditText.Here I am having a problem regarding imeoptions.my requirement is : actionDone should never be visible to user when toggle softkeyboard.always actionNext should be visible. What i am facing is: when user toggle keyboard,for first time it shows actionNext but when user type data and then click on keyboard toggler it is showing actionDone option.but here i want actionNext only.Beside,if the user clears the field and again toggle keyboard it is showing actionDone only but not actionNext. conclusion:i want only the actionNext in any scenario. this is my code for toggling softkeyboard:

btn_keyboard.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
         //actv_ServiceLoc.setInputType(InputType.TYPE_CLASS_TEXT);
         InputMethodManager inputMgr = (InputMethodManager)                      
           getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
         //inputMgr.toggleSoftInput(EditorInfo.IME_ACTION_NEXT,   
          EditorInfo.IME_ACTION_DONE);
      inputMgr.toggleSoftInput
       (EditorInfo.IME_FLAG_NO_ENTER_ACTION,EditorInfo.IME_ACTION_DONE);
       //actv_ServiceLoc.setText("");

        actv_ServiceLoc.requestFocus();
       if(actv_ServiceLoc.getText().toString().length()==0) {
        actv_ServiceLoc.setImeOptions(EditorInfo.IME_ACTION_NEXT);
         }
         else
              {
           actv_ServiceLoc.setImeOptions(EditorInfo.IME_ACTION_NEXT);

              }
         actv_ServiceLoc.setFocusableInTouchMode(true);
               location_error.setVisibility(myView.GONE);

                  }
               });

Thanks in advance.

Upvotes: 0

Views: 1090

Answers (2)

Rushi Ayyappa
Rushi Ayyappa

Reputation: 2848

writing below single line before toggling keyboard helps you show always 'actionNext' button in your keyboard.

actv_ServiceLoc.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
//your ui control.setInputType(InputType.YourFlag);

Upvotes: 0

Androider
Androider

Reputation: 3873

Infact, we cannot disable done(enter) action button on the android keyboard.

But we can only disable next button by adding android:imeOptions="actionDone" to your EditText.

Then also the last solution to control done button is to use the following block of code:

EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {

  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
      // your additional processing... 
      return true;
    } else {
      return false;
    }
  }
});

Upvotes: 1

Related Questions