Question: the id name is also the same id in the menu setting file; it is the same ID name and also imports the R; but

the id name is also the same id in the menu setting file; it is the same ID name and also imports the R; but also shows errors.... please give the reason and solution with R.id..... statement; the R.id.action_home always has errors although I import the R; please provide the solution with R.id.....statements;
package com.example.dropdown;
import static com.example.dropdown.R.*;
import com.example.dropdown.R;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
private boolean onMenuItemClick(MenuItem menuItem){
switch (menuItem.getItemId()){
case R.id.action_home:
Toast.makeText(this,"Home clicked", Toast.LENGTH_SHORT).show();
break;
case R.id.action_light_mode:
Toast.makeText(this,"Light Mode activated", Toast.LENGTH_SHORT).show();
setLightMode();
break;
case R.id.action_dark_mode:
Toast.makeText(this,"Dark Mode activated", Toast.LENGTH_SHORT).show();
setDarkMode();
break;
default:
return false;
}
return true;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!