0

我有一个获取功能,我正在尝试调用它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.

4

1 回答 1

0

已解决首先从我的 basefragment 创建了一个函数

  @Override
  public void updateToolbar(Toolbar toolbar) {

 setTitle( R.string.title_transaction_history );
 Drawable drawablew =
 ContextCompat.getDrawable(getApplicationContext(),R.drawable.ic_icon_filter);
 toolbar.setOverflowIcon(drawablew);
}

然后它对我有用。

于 2018-08-08T21:18:45.323 回答