I have an EditText object in one of my activities. I have implemented the code to insert a "Done" button on the keyboard, and hide it when the user's done typing. I've noticed though, that the text is not being auto-returned when it reaches the maximum length I've attached to the EditText object. In my iPhone version of this app, I've been able to set an attribute called "auto-return" for my text box that automatically returns, and this is what I would like to implement for the Android version, but I don't know how. Here is the code I've written:
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:maxLength="10"
android:hint="@string/hint"
android:inputType="textImeMultiLine"
android:imeOptions="actionDone"
android:layout_marginTop="15dp"
android:gravity="center"/>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_type_order);
getActionBar().setDisplayHomeAsUpEnabled(true);
editText1 = (EditText)findViewById(R.id.editText1);
editText1.setLines(10);
editText1.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
InputMethodManager keyboard1 = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
keyboard1.hideSoftInputFromInputMethod(editText1.getWindowToken(), 0);
}
});