0

I have menu item (icons) like a gMail, I have a menu item and when I long click I see a toast. I tried blocking this:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MainActivity.menu = menu;
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        MenuItem searchItem = menu.findItem(R.id.action_search);

        new Handler().post(new Runnable() {
            @Override
            public void run() {
                final View v = findViewById(R.id.action_search);

                if (v != null) {
                    v.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View v) {
                            return false;
                        }
                    });
                }
            }
        });

        new Handler().post(new Runnable() {
            @Override
            public void run() {
                final View v = findViewById(R.id.action_search1);

                if (v != null) {
                    v.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View v) {
                            return false;
                        }
                    });
                    v.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            return;
                        }
                    });
                }
            }
        });

        SearchView searchView = (SearchView) searchItem.getActionView();

        if (searchView != null) {
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); return true; }

                @Override
                public boolean onQueryTextChange(String s) {
                    if (sp.getInt("filtr", 0) == 1) {
                        ArrayList<RowEntity> rows = new ArrayList<>();
                        for (RowEntity r : rowEntities) {
                            if (r.getStatus() != 1) {
                                rows.add(r);
                            }
                        }
                        ExpandableListAdapter.mStringFilterList = rows;
                    } else {
                        ExpandableListAdapter.mStringFilterList = rowEntities;
                    }
                    search.setSearch(s.toString());
                    expandableListAdapter.getFilter().filter(s.toString());
                    expandableListAdapter.notifyDataSetChanged();
                    expandableListView.invalidateViews();
                    return false;
                }
            });
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
//        switch (id) {
//            case R.id.all:
//                sortList(true);
//                break;
//            case R.id.not_done:
//                sortList(false);
//                break;
//        }

        return super.onOptionsItemSelected(item);
    }

But When I use a search view and click an icon I see a toast.
How can I block this?
I don't want to see a toast which name of item

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • This is an android specific mechanism which shouldn't be blocked. But maybe you can remove the text tag of your menuitems from your menu layout. – Oliver Adam Dec 04 '17 at 08:25
  • @OliverAdam When remove tille in my menu items I see a empty toast –  Dec 04 '17 at 08:28
  • 1
    Maybe this will help you: https://stackoverflow.com/questions/17408365/hiding-of-the-toast-for-long-press-on-actionbar-item – Oliver Adam Dec 04 '17 at 08:29

0 Answers0