gpt4 book ai didi

java - 方法不会覆盖其父类(super class)中的方法

转载 作者:行者123 更新时间:2023-12-01 06:49:36 24 4
gpt4 key购买 nike

我正在尝试设置操作栏的标题,但它给了我错误消息“方法不会覆盖其父类(super class)中的方法”。我正在扩展 fragment 。

这是我遇到问题的部分:

@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActivity().getActionBar().setTitle(mTitle);
}

这是整个类的代码(它不完整,因为我仍在研究它):

package com.android.styles.radius360;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.Menu;


/**
* Created by user on 3/23/2017.
*/

public class HomePageFragment extends Fragment {

private String[] mOptions;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private CharSequence mTitle;

private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.home_page, container, false);

mOptions = getResources().getStringArray(R.array.options_array);
mDrawerLayout = (DrawerLayout) v.findViewById(R.id.drawer_layout);
mDrawerList = (ListView) v.findViewById(R.id.left_drawer);

// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<String>(getActivity(),
R.layout.drawer_list_item, mOptions));
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

mTitle = mDrawerTitle = getActivity().getTitle();
mDrawerLayout = (DrawerLayout) v.findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout,
R.string.drawer_open, R.string.drawer_close) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActivity().getActionBar().setTitle(mTitle);
getActivity().invalidateOptionsMenu(); // Creates call to onPrepareOptionsMenu()
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getActivity().getActionBar().setTitle(mDrawerTitle);
getActivity().invalidateOptionsMenu(); // Creates call to onPrepareOptionsMenu()
}
};

// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);

return v;
}

@Override
public void onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content view
super.onPrepareOptionsMenu(menu);
}

@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActivity().getActionBar().setTitle(mTitle);
}


/* The click listner for ListView in the navigation drawer */
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}

/** Swaps fragments in the main content view */
private void selectItem(int position) {
// Create a new fragment and specify the planet to show based on position
if(position == 0)
{
FragmentManager fragmentManager = getFragmentManager();

SettingsPageActivity settings = new SettingsPageActivity();
Fragment fragment = settings.createFragment();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();

}
// Insert the fragment by replacing any existing fragment

// Highlight the selected item, update the title, and close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerLayout.closeDrawer(mDrawerList);
}

}

最佳答案

Fragment 或其任何父类(super class)似乎没有方法 public void setTitle(CharSequence title) 因此您不能使用 @覆盖注释。您可以删除该注释,应该没问题。

关于java - 方法不会覆盖其父类(super class)中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43056341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com