1

Can I prevent space for first word in EditText without write a code? If I will write a code for this problem, Can I define in onCreate method?

<EditText
        android:id="@+id/aranacak_film"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center_horizontal"
        android:maxLines="1"
        android:maxLength="20"
        android:inputType="text"
        android:hint="ARANACAK FİLM">
</EditText>
Ashish
  • 6,791
  • 3
  • 26
  • 48
Kamil
  • 175
  • 1
  • 1
  • 10

1 Answers1

0

Use TextWatcher For your Edittext :

aranacak_film.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                //
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                if(s.toString().equals(" "))
                {
                    aranacak_film.setError("Space is not allowed");
                    aranacak_film.setText("");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {    
                //
            }
        });
Kamil
  • 175
  • 1
  • 1
  • 10
Ashish
  • 6,791
  • 3
  • 26
  • 48