0

EditText

<android.support.v7.widget.AppCompatEditText
            android:id="@+id/itemEditText_id"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:layout_marginTop="8dp"
            android:layout_marginStart="2dp"
            android:layout_marginEnd="4dp"
            android:lines="2"
            android:scrollHorizontally="false"
            android:maxLength="69"
            android:scrollbars="vertical"
            android:background="@drawable/round_border_edit_text"
            android:hint="Go ahead \nSend messge"
            android:inputType="textMultiLine|textLongMessage"
            android:textAppearance="@style/TextAppearance.AppCompat.Body2"
            android:maxLines="2"
            android:minLines="1"
            />

this is my xml code if something needs to be added or removed here please tell.

java code which i'm using to achieve what i want like whatsapp's editText but its not working quite well

final AppCompatEditText editText = holder.itemEditText;

        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {



                // if edittext has 10chars & this is not called yet, add new line
                if(editText.getText().length() == 34 && !isReached) {

                    editText.append("\n");
                    isReached = true;

                }
                // if edittext has less than 10chars & boolean has changed, reset
                if(editText.getText().length() < 34 && isReached) isReached = false;

                Log.d("char", "onTextChanged: "+charSequence);
                Log.d("i", "onTextChanged: "+i);
                Log.d("i1", "onTextChanged: "+i1);
                Log.d("i2", "onTextChanged: "+i2);

            }

            @Override
            public void afterTextChanged(Editable editable) {


            }
        });

    }

this code is not working like i want it to or you can say i'm not being able to code the way i want editText to act.

i want my editText to work like Whatsapp's editText like when i type something and it reaches to the icon inside the editText, cursor goes to a new line with the typing word. In my editText the words are going underneath the ImageButton which im using as a send icon. i dont want the words to go underneath the send icon. Please Help.

ImageButton

 <android.support.v7.widget.AppCompatImageButton
            android:id="@+id/itemSendButton_id"
            android:layout_width="25dp"
            android:layout_height="20dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_marginEnd="11dp"
            android:background="@color/colorFacebookBtnText"
            android:clickable="true"
            android:focusable="true"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_send" />

i'm new to programming so please help me out and thanks in advance.

Aditya Tandon
  • 650
  • 1
  • 5
  • 8

1 Answers1

0

Use this

et1.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start,int before, int count) 
{
    // TODO Auto-generated method stub
    if(et1.getText().toString().length()==size)     //size as per your requirement
    {
        et2.requestFocus();
    }
}
public void beforeTextChanged(CharSequence s, int start,
                int count, int after) {
            // TODO Auto-generated method stub

}

public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
}

});
ADM
  • 20,406
  • 11
  • 52
  • 83
  • i don't want my cursor to go to next editText. i want my cursor to go to the new line inside the same editText along with the typing word – Aditya Tandon May 07 '18 at 11:28