D
D
dangerclose2014-06-02 12:26:20
Android
dangerclose, 2014-06-02 12:26:20

How to fix error when adding menu items?

I want to add 2 menu items

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        
        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setQueryHint("Поиск");
        searchView.setOnQueryTextListener(this);
        return true;
    
       
      
           
      MenuItem item = (MenuItem) menu.findItem(R.id.action_share);
      ShareActionProvider shareAction = (ShareActionProvider) MenuItemCompat
              .getActionProvider(item);
      Intent shareIntent = new Intent(Intent.ACTION_SEND)
              .setAction(Intent.ACTION_SEND)
              .putExtra(Intent.EXTRA_TEXT, "а")
              .setType("text/plain");
      shareAction.setShareIntent(shareIntent);
      return super.onCreateOptionsMenu(menu);
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anonbright, 2014-06-02
@anonbright

Show error in log

E
Edward, 2014-06-09
@ED98

Maybe return true in the middle is not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question