[英]Override deprecated method in android.support.v4.app.fragment
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
activitycomander = (TopSectionListener) activity;
}catch (ClassCastException e){
throw new ClassCastException(activity.toString());
}
}
This is the code of my java class linking with MainActivity.这是我的 java 类与 MainActivity 链接的代码。 There is issue with
onAttach
method in Android Studio. Android Studio 中的
onAttach
方法存在问题。 It shows as strike-through with the message:它显示为带有删除线的消息:
onAttach
(android.app.activity
) is deprecated:onAttach
(android.app.activity
) 已弃用:
I'm also having a second issue in MainActivity:我在 MainActivity 中还有第二个问题:
public void createMeme(String top, String bottom){
bottomsection fragmentbottom = (bottomsection) getSupportFragmentManager().findFragmentById(R.id.fragment2);
fragmentbottom.setMemeText(top, bottom);
}
topsection
and bottomsection
are the names of my java classes, they are highlighted red with the message cannot resolve method
. topsection
和bottomsection
是我的 Java 类的名称,它们以红色突出显示,并带有消息cannot resolve method
。
I have done a clean rebuild on my project and checked the option to add or remove the imports automatically.我已经对我的项目进行了干净的重建,并检查了自动添加或删除导入的选项。
First question regarding onAttach
is a duplicate of Android Fragment onAttach() deprecated关于
onAttach
第一个问题是Android Fragment onAttach() deprecated的副本
Regarding topsection
and bottomsection
, Classes should always begin with a capital letter and use CamelCaps, as per the Naming Conventions .关于
topsection
和bottomsection
,根据命名约定,类应始终以大写字母开头并使用 CamelCaps 。 So rename them to TopSection
and BottomSection
.所以将它们重命名为
TopSection
和BottomSection
。
Also check if your class has been imported - if bottomsection
is underlined then try Alt+Enter and select Import Class还要检查您的课程是否已导入 - 如果
bottomsection
有下划线,则尝试Alt+Enter并选择导入课程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.