Tôi tìm kiếm rất nhiều trên mạng nhưng không có gì ngăn cản menu bật lên đóng.Cách ngăn menu bật lên đóng hộp kiểm tra
Bất cứ khi nào tôi nhấp vào mục hộp kiểm hoặc bất kỳ mục menu popup nào khác, trình đơn bật lên sẽ tự bỏ qua. Làm thế nào tôi có thể ngăn chặn nó từ bỏ khi người dùng kiểm tra/bỏ chọn hộp kiểm trong menu popup.
Tôi đang hiển thị menu bật lên trên sự kiện nhấp chuột của mục menu của mục tác vụ.
//main_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.worldofjobs.woj.MainActivity" >
<item
android:id="@+id/action_popUpMenu"
android:icon="@drawable/ic_action_overflow"
android:title="@string/main_action_popUpMenu"
app:showAsAction="always"/>
</menu>
//popup_items.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/refresh_item"
android:title="@string/main_refresh"/>
<item
android:id="@+id/checkbox_item"
android:checkable="true"
android:title="Start notification"/>
<item
android:id="@+id/changePasswrod_item"
android:title="@string/main_changePassword"/>
<item
android:id="@+id/deleteAccount_item"
android:title="@string/main_deleteAccount"/>
<item
android:id="@+id/logout_item"
android:title="@string/main_logout"/>
</menu>
/**
* Shows popup menu on click of action bar-menu inflates from
* menu.pop_items-xml
*/
private void showPopup() {
try {
View v = findViewById(R.id.action_popUpMenu);
PopupMenu popup = new PopupMenu(this, v);
popup.setOnMenuItemClickListener(MainActivity.this);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.pop_items, popup.getMenu());
popup.show();
} catch (Exception e) {
Log.e("MainActivity-showPopup:", e.toString());
}
}
/**
* Handles click events of popup menu items
*/
@Override
public boolean onMenuItemClick(MenuItem item) {
super.onMenuItemSelected(1, item);
switch (item.getItemId()) {
case R.id.refresh_item:
refresh();
return true;
case R.id.checkbox_item:
return true;
case R.id.changePasswrod_item:
changePasswordPopup();
return true;
case R.id.deleteAccount_item:
deleteAccount();
return true;
case R.id.logout_item:
session.logout();
finish();
return true;
}
return true;
}
Mã hộp kiểm tra ở đâu, Vui lòng đăng mã hoàn chỉnh. –
Kiểm tra mã cập nhật của tôi (notification_item - checkbox_item). checkbox_item là mục menu popup có thể kiểm tra. Tôi đã không làm bất cứ điều gì được nêu ra trên đó là sự kiện click/check cho đến khi nó dừng đóng menu popup. – Sushant
@ sushant- Chế độ xem giữ trong v –