[英]Unable to add a button in fragment using Navigation storyboard to jump from one fragment to another fragment
I am trying to add a button in a fragment page to jump from one fragment to another fragment using the method of the navigation storyboard of android studio. 我试图在片段页面中添加一个按钮,以使用android studio导航情节提要的方法从一个片段跳转到另一个片段。 However, in the Mainfragment.java, my button id cannot be resolved, it cannot recognize my button id and I don't know why.
但是,在Mainfragment.java中,我的按钮ID无法解析,无法识别我的按钮ID,也不知道为什么。 Please help!
请帮忙!
public MainFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_main, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Button goToBtn = (Button) this.findViewById(R.id.goToBtn);
goToBtn.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.toAccount, null));
}
}
For the above codes in Mainfragment.java
, the findViewById
is red. 对于
Mainfragment.java
的上述代码, findViewById
为红色。
change below line 在行下更改
Button goToBtn = (Button) this.findViewById(R.id.goToBtn);
With 同
Button goToBtn = (Button) view.findViewById(R.id.goToBtn);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.