0

Im trying to use the .show() method for my AndroidStudio but .show() is showing up in red. I tried looking up to see if I was missing any dependencies but it seems correct, at least from my perspective. Im trying to learn Android Studio. I will attach the code below. Any assistance would be great!

    private void saveToDo(){
        String description = editTextDescription.getText().toString();

        //the following to get the date chosen in datepicker abd store it in a Date type attribute
        int year = datePickerDueDate.getYear();
        int month = datePickerDueDate.getMonth();
        int day = datePickerDueDate.getDayOfMonth();
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day);

        Date dueDate=calendar.getTime();

        if(description.trim().isEmpty()){
            Toast.makeText(this, "Please enter a description!", Toast.LENGTH_SHORT.show()); //Show method not working
        }
        Intent data = new Intent();
        data.putExtra(EXTRA_DESCRIPTION, description);
        data.putExtra(EXTRA_DUEDATE, dueDate);

        setResult(RESULT_OK,data);
        finish();```
Zain
  • 37,492
  • 7
  • 60
  • 84

3 Answers3

2

show() should be outside the makeText function

 Toast.makeText(this, "Please enter a description!", Toast.LENGTH_SHORT).show();
anehme
  • 536
  • 1
  • 6
  • 18
2
Toast.makeText(this, "Please enter a description!", Toast.LENGTH_SHORT.show());

change to

Toast.makeText(this, "Please enter a description!", Toast.LENGTH_SHORT).show();
S T
  • 1,068
  • 2
  • 8
  • 16
1

the following code :-

    if(description.trim().isEmpty()){
        Toast.makeText(this, "Please enter a description!", Toast.LENGTH_SHORT.show()); //Show method not working
    }

should be changed to :-

    if(description.trim().isEmpty()){
        Toast.makeText(this, "Your Description !", Toast.LENGTH_SHORT).show(); // this will work  
    } //Toast.LENGTH_SHORT is alternative n
Parth B Thakkar
  • 115
  • 2
  • 10