Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

java - onOptionsItemsSelected cannot be overridden and is unused?

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);
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is onOptionsItemSelected - Item, not Items.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...