0

when i am trying to insert key events in android import android.view.KeyEvent; is not working, got this Cannot resolve symbol 'KeyEvent' when import java lib.

import android.view.KeyEvent;

 view.setOnKeyListener( new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if( keyCode == KeyEvent.KEYCODE_BACK){
                    new AlertDialog.Builder(getContext())
                            .setIcon(R.drawable.pause)
                            .setTitle("PAUSE")
                            .setMessage("Are you sure you want to Pause this test?")
                            .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                            {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    //finish();
                                }

                            })
                            .setNegativeButton("No", null)
                            .show();
                }
                return false;
            }
        });

Cannot resolve symbol 'KeyEvent'
  • 1
    Are you sure you are importing this *Outside* your class? Can you show the whole class? – Zohaib Amir Jul 31 '19 at 18:29
  • import android.os.CountDownTimer; import android.text.Html; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View;@ZohaibAmir – UdaipurEscorts Jul 31 '19 at 18:33
  • Maybe this will help: https://stackoverflow.com/questions/18991161/android-studio-cannot-resolve-symbol-but-code-executes-correctly – Livio Tonini Aug 01 '19 at 16:58

0 Answers0