Jaya Mayu
Jaya Mayu

Reputation: 17257

Android: Onclick listener for EditText

Following is my code. When I click the EditText system doesn't trigger the intent, instead it brings up the keyboard on second click only it triggers the intent. How to make sure it happens on first click.

description.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                //Toast.makeText(sendingpage.this, description.getText(), 2000).show();
                Intent fullscreen = new Intent(sendingpage.this, ShowSummeryActivity.class);;
                startActivity(fullscreen);

            }
        });

Thanks for your time in advance.

Upvotes: 2

Views: 5836

Answers (3)

Muhammad Nouman
Muhammad Nouman

Reputation: 211

you can use onTouchListener intead of onClickListener!!

  description.setOnTouchListener { view, motionEvent ->
            if (motionEvent.action==MotionEvent.ACTION_UP){
               // you can set the intent here!!
            }
            false
        }

This code is in Kotlin you can change this code to Java.

Upvotes: 0

dvrm
dvrm

Reputation: 3759

i had the same problem the solution is (with warpzit comment help) to add android:focusable="false" and android:focusableInTouchMode="false" this solved my issue easily

Upvotes: 6

iDroid
iDroid

Reputation: 10533

I don't know why you get this behaviour, i got the same code and it works fine both on emulator and HTC device. Anyway you can hide the soft keyboard manually by using the InputMethodManager. Add this to your onClick method.

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(description.getWindowToken(), 0);

Upvotes: 1

Related Questions