I am trying to create a popup menu, but i am getting this error, saying "unknown member 'menu' of com.popup.trial.R
What should I do?
my xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/one"
android:title="One"/>
<item
android:id="@+id/two"
android:title="Two"/>
</menu>
and my java:
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(MainActivity.this, settings2);
popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(MainActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
}
});
The R
class is code-generated for you by the Android build tools when you build your project.
Clean
your project or Build
your projectreference : Beginner Android why is "id" is "Unknown member" with R.id?
follow this link for other example. : https://www.javatpoint.com/android-popup-menu-example