我有一个获取功能,我正在尝试调用它onCreateOptionsMenu(Menu menu, MenuInflater inflater)
来实时填充菜单。switch
此功能在溢出菜单中运行良好,但在我的块中不起作用。我正在尝试正确调用此函数并在单击我的新图标时运行它。任何想法?
private void fetchMembers(Menu menu) {
@Override
public void onNext(ListMembersResponse response) {
if (response.members != null && !response.members.isEmpty()) {
for (int i = 0; i < response.members.size(); i++) {
Merchant merchant = response.members.get(i);
menu.add( Menu.NONE, i, Menu.NONE, merchant.firstName + " " + merchant.lastName); ///here is fetching full name
}
}
}
我的switch
块:
switch (item.getItemId())
{
case R.id.menu_item_filter:
fetchMembers(menu);
case R.id.menu_item_search:
if (!TextUtils.isEmpty(item.getTitle())) {
trackEvent(AnalyticsManager.CATEGORY_HISTORY_SEARCH,
AnalyticsManager.ACTION_TRIGGERED,
AnalyticsManager.LABEL_TRIGGERED);
String newText = String.valueOf(item.getTitle());
String text = newText.trim().toLowerCase(Locale.getDefault());
return true;
} else {
paymentsAdapter.filter("");
itemManager.expandGroup(0);
scrollListener.setEndlessScrollEnabled(true);
return true;
}
}
return false; //true
PS:我试图用另一个改变我的溢出图标:
Drawable drawable =
ContextCompat.getDrawable(getApplicationContext(),R.drawable.change_pass);
toolbar.setOverflowIcon(drawable);
但它也不起作用。错误是一个NullPointerException
.