[英]redirection from one fragment to another by clicking a button in one fragment together with changing the bottom navigation icon in android studio
[英]Unable to add a button in fragment using Navigation storyboard to jump from one fragment to another fragment
我試圖在片段頁面中添加一個按鈕,以使用android studio導航情節提要的方法從一個片段跳轉到另一個片段。 但是,在Mainfragment.java中,我的按鈕ID無法解析,無法識別我的按鈕ID,也不知道為什么。 請幫忙!
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));
}
}
對於Mainfragment.java
的上述代碼, findViewById
為紅色。
在行下更改
Button goToBtn = (Button) this.findViewById(R.id.goToBtn);
同
Button goToBtn = (Button) view.findViewById(R.id.goToBtn);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.