0
Menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:checkableBehavior="single">
<item
android:id="@+id/one"
android:title="One"
/>
<item
android:id="@+id/two"
android:title="Two"
tools:ignore="AppCompatResource" />
<item
android:id="@+id/three"
android:title="Three"
/>
</group>
</menu>
Java:
btntimer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(ChuvaLeveActivity.this, btntimer);
popup.inflate(R.menu.action);
// This activity implements OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.one:
Toast.makeText(getApplicationContext(), "ONE", Toast.LENGTH_SHORT).show();
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
case R.id.two:
Toast.makeText(getApplicationContext(), "TWO", Toast.LENGTH_SHORT).show();
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
case R.id.three:
Toast.makeText(getApplicationContext(), "THREE", Toast.LENGTH_SHORT).show();
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
default:
return false;
}
}
});
popup.show();
}
});
Hit the fly! Heheh, so every time I clicked the button it called the reset menu? Thank you very much! It was all afternoon. :)
– Juliano Souza