onOptionsItemsSelected cannot be overridden and is unused? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of onOptionsItemsSelected cannot be overridden and is unused? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

So I’ve been searching the internet for hours and cannot find a solution. It would appear I am having two issues with this code, the first one being the @Override for onOptionsItemsSelected (Method does not override method from it’s superclass) and second being the onOptionsItemsSelected itself. onOptionsItemsSelected tells me the method is never used, which I thought might be why I am having the issue with @Override. I’m just not sure what it is I am overlooking. I have provided the java code below, if the xml code is needed let me know and I’ll post it asap. Thanks in advance.

package com.example.main_navigation;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class WalletActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wallet);
    }

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.actionbar_menu, menu);
        return true;
    }
    @Override  ///First issue is here and 2nd issue is right below this line
    protected boolean onOptionsItemsSelected(final MenuItem item) {

        final int id = item.getItemId();
        if (id == R.id.action_custom_button) {
            startActivity(new Intent(getApplicationContext(), NavigationActivity.class));
            overridePendingTransition(0, 0);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

Answer

It is onOptionsItemSelected – Item, not Items.

We are here to answer your question about onOptionsItemsSelected cannot be overridden and is unused? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji