0

I am using Butterknife and trying to change on EditText the enter for a submit

<EditText
android:id="@+id/id_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/gray_line_background"
android:ems="10"
android:gravity="top"
android:inputType="textMultiLine"
android:minLines="8" />

and in my fragment

@InjectView(R.id.id_message)
@NotEmpty(messageResId = R.string.err_message_empty)
EditText message;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_myfragment, container, false);
      ButterKnife.inject(this, v);

      validator = new Validator(this);
      validator.setValidationListener(this);

      message.setImeActionLabel("Submit", KeyEvent.KEYCODE_ENTER);

      message.setOnEditorActionListener(new EditText.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (actionId == EditorInfo.IME_ACTION_DONE) {
                  onNextClick(message);
                  return true;
              }
              return false;
          }
      });


    return v;
}

Is not working neither of the things the button doesn't change the text, and the listener doesn't perform the action

Thank you

agusgambina
  • 6,229
  • 14
  • 54
  • 94
  • You can try to move your code to the onViewCreated method of the fragment. I think the views may have not been properly inflated at the time you're injecting it. – mmark Mar 18 '15 at 22:25
  • @urudroid thank you, I tried and wasn't that. Now I will post the answer. – agusgambina Mar 24 '15 at 22:15

1 Answers1

1

The problem was not ButterKnife, the problem was in the xml

android:inputType="textMultiLine"

With that line didn't change the enter, so I managed programmatically and worked

@InjectView(R.id.id_message)
@NotEmpty(messageResId = R.string.err_message_empty)
EditText message;

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_preclass3, container, false);
    ButterKnife.inject(this, v);

    message.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    message.setImeActionLabel("Enviar", EditorInfo.IME_ACTION_DONE);
    message.setImeOptions(EditorInfo.IME_ACTION_DONE);
    message.setLines(8);

    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                onNextClick(message);
                handled = true;
            }
            return handled;
        }
    });


    return v;
}

Thank you

agusgambina
  • 6,229
  • 14
  • 54
  • 94