1

hi am trying to allow the user to change the delay time after an action is performed on button click..i tried this where time is the Edit Text and used time instead of a number under the handler.

Long delay=time.getText().toString().trim();

but i am getting and error incompatible types if anyone have a solution for this please help i know it is simple but i am not getting it.

code

 b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {



            String tittle=ed1.getText().toString().trim();
            String subject=ed2.getText().toString().trim();
            String body=ed3.getText().toString().trim();

            NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notify=new Notification(R.drawable.noti,tittle,System.currentTimeMillis());
            PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);

            notify.setLatestEventInfo(getApplicationContext(),subject,body,pending);
            notif.notify(0, notify);
                }
            }, 12000);
        }
    });
Mrad4Tech
  • 205
  • 2
  • 12

1 Answers1

1

The incompatible types error is because you are assigning a String value to a long variable. You have to convert the String value to long before you can store it in delay variable.

Do something like

String delayStr = time.getText().toString().trim();
long delay = Long.parseLong(delayStr);

or in one line

long delay = Long.parseLong(time.getText().toString().trim());
Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41