w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Android onclicklistener doesn't work the first time when clicked

Set focusable on EditText to false. First click gains focus to EditText.

<EditText
                    android:id="@+id/step"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginTop="5dp"
                    android:hint="@string/hnt_message"
                    android:text="Default text"
                    android:maxLength="@integer/max_free_msg_length"
                    android:maxLines="2"
android:focusable="false"
                    />

UPDATE: Ok, in your case you can do it with onFocusChangeListnere instead of onClickListener.

edittext.setOnFocusChangeListener(new
View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                if (b) {
                    //do something
                }
            }
        });




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.